diff --git a/src/useFullscreen.ts b/src/useFullscreen.ts index f795bb3b14..a7d238ec6c 100644 --- a/src/useFullscreen.ts +++ b/src/useFullscreen.ts @@ -11,7 +11,7 @@ export interface FullScreenOptions { } const useFullscreen = ( - ref: RefObject, + ref: RefObject, enabled: boolean, options: FullScreenOptions = {} ): boolean => { @@ -48,7 +48,7 @@ const useFullscreen = ( screenfull.request(ref.current); setIsFullscreen(true); } catch (error) { - onClose(error); + onClose(error as Error); setIsFullscreen(false); } screenfull.on('change', onChange); diff --git a/tests/useFullscreen.test.ts b/tests/useFullscreen.test.ts new file mode 100644 index 0000000000..d849607a78 --- /dev/null +++ b/tests/useFullscreen.test.ts @@ -0,0 +1,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(); + const { result } = renderHook(() => useFullscreen(ref, false)); + + expect(result.current).toBe(false); + }); + + it('should return a boolean value', () => { + const ref = createRef(); + const { result } = renderHook(() => useFullscreen(ref, true)); + + expect(typeof result.current).toBe('boolean'); + }); + + it('should accept options parameter', () => { + const ref = createRef(); + const options = { onClose: jest.fn() }; + const { result } = renderHook(() => useFullscreen(ref, true, options)); + + expect(typeof result.current).toBe('boolean'); + }); +});