Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/useFullscreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface FullScreenOptions {
}

const useFullscreen = (
ref: RefObject<Element>,
ref: RefObject<HTMLElement | null>,
enabled: boolean,
options: FullScreenOptions = {}
): boolean => {
Expand Down Expand Up @@ -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);
Expand Down
56 changes: 56 additions & 0 deletions tests/useFullscreen.test.ts
Original file line number Diff line number Diff line change
@@ -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<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');
});
});