-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathuseTitle.test.ts
28 lines (23 loc) · 968 Bytes
/
useTitle.test.ts
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
import { renderHook } from '@testing-library/react-hooks';
import useTitle from '../src/useTitle';
describe('useTitle', () => {
it('should be defined', () => {
expect(useTitle).toBeDefined();
});
it('should update document title', () => {
const hook = renderHook((props) => useTitle(props), { initialProps: 'My page title' });
expect(document.title).toBe('My page title');
hook.rerender('My other page title');
expect(document.title).toBe('My other page title');
});
it('should restore document title on unmount', () => {
renderHook((props) => useTitle(props), { initialProps: 'Old Title' });
expect(document.title).toBe('Old Title');
const hook = renderHook((props) => useTitle(props.title, { restoreOnUnmount: props.restore }), {
initialProps: { title: 'New Title', restore: true },
});
expect(document.title).toBe('New Title');
hook.unmount();
expect(document.title).toBe('Old Title');
});
});