mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
Also reduce max line width to 100. And remove `lint:types` step for commit sequence, it bothers when committing incomplete (wip) changes.
29 lines
968 B
TypeScript
29 lines
968 B
TypeScript
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');
|
|
});
|
|
});
|