mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 09:30:31 +03:00
Created ErrorHandler test
This commit is contained in:
parent
cd908fa358
commit
ad9f0c00d0
2 changed files with 36 additions and 1 deletions
|
@ -14,7 +14,6 @@ const ErrorHandler = ({ location }) => class ErrorHandler extends React.Componen
|
||||||
}
|
}
|
||||||
|
|
||||||
static getDerivedStateFromError() {
|
static getDerivedStateFromError() {
|
||||||
// Update state so the next render will show the fallback UI.
|
|
||||||
return { hasError: true };
|
return { hasError: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
36
test/common/ErrorHandler.test.js
Normal file
36
test/common/ErrorHandler.test.js
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue