shlink-web-client/test/common/ErrorHandler.test.js
2019-03-04 20:49:18 +01:00

36 lines
1,006 B
JavaScript

import React from 'react';
import { shallow } from 'enzyme';
import { Button } from 'reactstrap';
import createErrorHandler from '../../src/common/ErrorHandler';
describe('<ErrorHandler />', () => {
const window = {
location: {
reload: jest.fn(),
},
};
let wrapper;
beforeEach(() => {
const ErrorHandler = createErrorHandler(window);
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(
'It seems that something went wrong. Try refreshing the page or just click this button.'
);
expect(wrapper.find(Button)).toHaveLength(1);
});
});