-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Expand file tree
/
Copy pathuseFullscreen.test.ts
More file actions
56 lines (45 loc) · 1.42 KB
/
useFullscreen.test.ts
File metadata and controls
56 lines (45 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { renderHook } from '@testing-library/react-hooks';
import { createRef } from 'react';
import useFullscreen from '../src/useFullscreen';
// Mock screenfull
const mockScreenfull = {
isEnabled: true,
isFullscreen: false,
request: jest.fn(),
exit: jest.fn(),
on: jest.fn(),
off: jest.fn(),
};
jest.mock('screenfull', () => mockScreenfull);
// Mock the on/off functions from misc/util
jest.mock('../src/misc/util', () => ({
noop: () => {},
on: jest.fn(),
off: jest.fn(),
}));
describe('useFullscreen', () => {
beforeEach(() => {
jest.clearAllMocks();
mockScreenfull.isEnabled = true;
mockScreenfull.isFullscreen = false;
});
it('should be defined', () => {
expect(useFullscreen).toBeDefined();
});
it('should return false when disabled', () => {
const ref = createRef<HTMLDivElement>();
const { result } = renderHook(() => useFullscreen(ref, false));
expect(result.current).toBe(false);
});
it('should return a boolean value', () => {
const ref = createRef<HTMLDivElement>();
const { result } = renderHook(() => useFullscreen(ref, true));
expect(typeof result.current).toBe('boolean');
});
it('should accept options parameter', () => {
const ref = createRef<HTMLDivElement>();
const options = { onClose: jest.fn() };
const { result } = renderHook(() => useFullscreen(ref, true, options));
expect(typeof result.current).toBe('boolean');
});
});