Skip to content

Commit de115a4

Browse files
author
Ayush Krishnatray
committed
adding test cases
1 parent a1df235 commit de115a4

File tree

9 files changed

+126
-2
lines changed

9 files changed

+126
-2
lines changed

.huskyrc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"hooks": {
3-
"pre-commit": "lint-staged",
4-
"pre-push": "npm run prePush"
3+
"pre-commit": "npm preCommit",
4+
"pre-push": "npm prePush"
55
}
66
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react';
2+
import { shallow, mount } from 'enzyme';
3+
import { shallowToJson } from 'enzyme-to-json';
4+
import ErrorBoundary from '../ErrorBoundary';
5+
6+
const Something = () => null;
7+
8+
describe('<ErrorBoundary> window', () => {
9+
it('should match the snapshot', () => {
10+
const tree = shallow(<ErrorBoundary>Test</ErrorBoundary>);
11+
expect(shallowToJson(tree)).toMatchSnapshot();
12+
});
13+
14+
it('should display an ErrorMessage if wrapped component throws', () => {
15+
const tree = mount(
16+
<ErrorBoundary>
17+
<Something />
18+
</ErrorBoundary>,
19+
);
20+
21+
const error = new Error('test');
22+
23+
tree.find(Something).simulateError(error);
24+
tree.setState({ hasError: true });
25+
expect(shallowToJson(tree)).toMatchSnapshot();
26+
});
27+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`<ErrorBoundary> window should display an ErrorMessage if wrapped component throws 1`] = `
4+
<ErrorBoundary>
5+
<h1>
6+
Something went wrong.
7+
</h1>
8+
</ErrorBoundary>
9+
`;
10+
11+
exports[`<ErrorBoundary> window should match the snapshot 1`] = `"Test"`;
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from 'react';
2+
// import { shallow } from 'enzyme';
3+
// import { shallowToJson } from 'enzyme-to-json';
4+
import renderer from 'react-test-renderer';
5+
6+
// Components
7+
import Footer from '../Footer';
8+
9+
10+
describe('Footer Test Suite', () => {
11+
it('renders correctly', () => {
12+
// const output = shallow(
13+
// <Footer />,
14+
// );
15+
const tree = renderer.create(<Footer />).toJSON();
16+
expect(tree).toMatchSnapshot();
17+
// expect(shallowToJson(output)).toMatchSnapshot();
18+
});
19+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Footer Test Suite renders correctly 1`] = `
4+
<footer>
5+
footer here
6+
</footer>
7+
`;
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react';
2+
import { shallow } from 'enzyme';
3+
import { shallowToJson } from 'enzyme-to-json';
4+
5+
// Components
6+
import Header from '../Header';
7+
8+
9+
describe('Header Test Suite', () => {
10+
it('renders correctly', () => {
11+
const output = shallow(
12+
<Header />,
13+
);
14+
expect(shallowToJson(output)).toMatchSnapshot();
15+
});
16+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Header Test Suite renders correctly 1`] = `
4+
<header>
5+
header here
6+
</header>
7+
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react';
2+
import { shallow } from 'enzyme';
3+
import { shallowToJson } from 'enzyme-to-json';
4+
5+
// Components
6+
import TestComponent from '../TestComponent';
7+
8+
9+
describe('TestComponent Test Suite', () => {
10+
it('renders correctly', () => {
11+
const onChange = jest.fn();
12+
const output = shallow(
13+
<TestComponent
14+
onChange={onChange}
15+
/>,
16+
);
17+
expect(shallowToJson(output)).toMatchSnapshot();
18+
output.find('input').simulate('change', { target: {} });
19+
expect(onChange).toBeCalled();
20+
});
21+
22+
it('should have default handleChange', () => {
23+
expect(TestComponent.defaultProps.onChange()).toBe(undefined);
24+
});
25+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`TestComponent Test Suite renders correctly 1`] = `
4+
<ErrorBoundary>
5+
<input
6+
onChange={[Function]}
7+
type="text"
8+
value=""
9+
/>
10+
<div />
11+
</ErrorBoundary>
12+
`;

0 commit comments

Comments
 (0)