2019-03-04 22:49:18 +03:00
|
|
|
import React from 'react';
|
2020-08-29 11:53:02 +03:00
|
|
|
import { shallow, ShallowWrapper } from 'enzyme';
|
2019-03-04 22:49:18 +03:00
|
|
|
import { Button } from 'reactstrap';
|
2020-08-29 11:53:02 +03:00
|
|
|
import { Mock } from 'ts-mockery';
|
2019-03-04 22:49:18 +03:00
|
|
|
import createErrorHandler from '../../src/common/ErrorHandler';
|
|
|
|
|
|
|
|
describe('<ErrorHandler />', () => {
|
2020-08-29 11:53:02 +03:00
|
|
|
const window = Mock.of<Window>({
|
2019-03-04 22:49:18 +03:00
|
|
|
location: {
|
|
|
|
reload: jest.fn(),
|
|
|
|
},
|
2020-08-29 11:53:02 +03:00
|
|
|
});
|
|
|
|
const console = Mock.of<Console>({ error: jest.fn() });
|
|
|
|
let wrapper: ShallowWrapper;
|
2019-03-04 22:49:18 +03:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2019-03-05 16:04:52 +03:00
|
|
|
const ErrorHandler = createErrorHandler(window, console);
|
2019-03-04 22:49:18 +03:00
|
|
|
|
|
|
|
wrapper = shallow(<ErrorHandler children={<span>Foo</span>} />);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => wrapper.unmount());
|
|
|
|
|
|
|
|
it('renders children when no error has occurred', () => {
|
|
|
|
expect(wrapper.text()).toEqual('Foo');
|
|
|
|
expect(wrapper.find(Button)).toHaveLength(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders error page when error has occurred', () => {
|
|
|
|
wrapper.setState({ hasError: true });
|
|
|
|
|
|
|
|
expect(wrapper.text()).toContain('Oops! This is awkward :S');
|
|
|
|
expect(wrapper.text()).toContain(
|
2020-08-22 09:10:31 +03:00
|
|
|
'It seems that something went wrong. Try refreshing the page or just click this button.',
|
2019-03-04 22:49:18 +03:00
|
|
|
);
|
|
|
|
expect(wrapper.find(Button)).toHaveLength(1);
|
|
|
|
});
|
|
|
|
});
|