1
|
|
|
import { shallow, ShallowWrapper } from 'enzyme'; |
2
|
|
|
import { Link } from 'react-router-dom'; |
3
|
|
|
import NotFound from '../../src/common/NotFound'; |
4
|
|
|
|
5
|
|
|
describe('<NotFound />', () => { |
6
|
|
|
let wrapper: ShallowWrapper; |
7
|
|
|
const createWrapper = (props = {}) => { |
8
|
|
|
wrapper = shallow(<NotFound {...props} />); |
9
|
|
|
const content = wrapper.text(); |
10
|
|
|
|
11
|
|
|
return { wrapper, content }; |
12
|
|
|
}; |
13
|
|
|
|
14
|
|
|
afterEach(() => wrapper?.unmount()); |
15
|
|
|
|
16
|
|
|
it('shows expected error title', () => { |
17
|
|
|
const { content } = createWrapper(); |
18
|
|
|
|
19
|
|
|
expect(content).toContain('Oops! We could not find requested route.'); |
20
|
|
|
}); |
21
|
|
|
|
22
|
|
|
it('shows expected error message', () => { |
23
|
|
|
const { content } = createWrapper(); |
24
|
|
|
|
25
|
|
|
expect(content).toContain( |
26
|
|
|
'Use your browser\'s back button to navigate to the page you have previously come from, or just press this button.', |
27
|
|
|
); |
28
|
|
|
}); |
29
|
|
|
|
30
|
|
|
it('shows a link to the home', () => { |
31
|
|
|
const { wrapper } = createWrapper(); |
32
|
|
|
const link = wrapper.find(Link); |
33
|
|
|
|
34
|
|
|
expect(link.prop('to')).toEqual('/'); |
35
|
|
|
expect(link.prop('className')).toEqual('btn btn-outline-primary btn-lg'); |
36
|
|
|
expect(link.prop('children')).toEqual('Home'); |
37
|
|
|
}); |
38
|
|
|
|
39
|
|
|
it('shows a link with provided props', () => { |
40
|
|
|
const { wrapper } = createWrapper({ to: '/foo/bar', children: 'Hello' }); |
41
|
|
|
const link = wrapper.find(Link); |
42
|
|
|
|
43
|
|
|
expect(link.prop('to')).toEqual('/foo/bar'); |
44
|
|
|
expect(link.prop('className')).toEqual('btn btn-outline-primary btn-lg'); |
45
|
|
|
expect(link.prop('children')).toEqual('Hello'); |
46
|
|
|
}); |
47
|
|
|
}); |
48
|
|
|
|