react-use/tests/useTitle.test.ts
xobotyi b6993a6f95
feat(prettier): make prettier a part of eslint.
Also reduce max line width to 100. And remove `lint:types` step for
commit sequence, it bothers when committing incomplete (wip) changes.
2021-02-01 18:58:55 +03:00

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');
});
});