Skip to content
This repository was archived by the owner on Mar 9, 2021. It is now read-only.

Commit b1572d0

Browse files
Zubair Ahmedvinaypuppal
Zubair Ahmed
authored andcommitted
add first test (#98)
* added enzyme * added all the revelant libs * added a sample test for common-banner component * removed redundant presets * removed babel/jest
1 parent bf7236b commit b1572d0

File tree

7 files changed

+307
-9
lines changed

7 files changed

+307
-9
lines changed

Diff for: .babelrc

+1-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
"presets": "next/babel"
88
},
99
"test": {
10-
"presets": [
11-
["env", { "modules": "commonjs" }],
12-
"next/babel"
13-
]
10+
"presets": [["env", { "modules": "commonjs" }], "next/babel"]
1411
}
1512
},
1613
"plugins": [

Diff for: __tests__/__snapshots__/common-banner.test.js.snap

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Testing CommonBanner of \`components/common-banner\` Check the snapshot 1`] = `
4+
<div
5+
className="jsx-1924801089"
6+
>
7+
<div
8+
className="jsx-1924801089 root"
9+
>
10+
<h1
11+
className="jsx-1924801089 headline"
12+
/>
13+
<h2
14+
className="jsx-1924801089"
15+
/>
16+
</div>
17+
<JSXStyle
18+
css=".root.jsx-1924801089{background-color:#f4f7fb;min-height:150px;text-align:center;padding-top:30px;padding-bottom:30px;}.headline.jsx-1924801089{font-size:4em;color:#df1cb5;font-weight:900;}h2.jsx-1924801089{max-width:1024px;margin-left:auto;margin-right:auto;-webkit-letter-spacing:2px;-moz-letter-spacing:2px;-ms-letter-spacing:2px;letter-spacing:2px;line-height:2;}@media (max-width:720px){h2.jsx-1924801089{font-size:14px;padding:0 10px;}}"
19+
styleId="1924801089"
20+
/>
21+
</div>
22+
`;

Diff for: __tests__/common-banner.test.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from 'react';
2+
import { shallow } from 'enzyme';
3+
4+
import CommonBanner from '../components/common-banner';
5+
6+
describe('Testing CommonBanner of `components/common-banner`', () => {
7+
const shallowWrapper = shallow(<CommonBanner />);
8+
9+
it('Check the snapshot', () => {
10+
expect(shallowWrapper).toMatchSnapshot();
11+
});
12+
13+
it('should have title tag rendered', () => {
14+
expect(shallowWrapper.find('h1').length).toBe(1);
15+
});
16+
17+
it('should have subtitle tag rendered', () => {
18+
expect(shallowWrapper.find('h2').length).toBe(1);
19+
});
20+
21+
describe('should render the props', () => {
22+
const pageTitle = 'title of the page';
23+
const pageSubTitle = 'Subtitle of the page';
24+
const rootWrapper = shallow(
25+
<CommonBanner pageTitle={pageTitle} pageSubTitle={pageSubTitle} />,
26+
);
27+
28+
it('should display title', () => {
29+
const headerElement = rootWrapper.find('.headline');
30+
expect(headerElement.props().children).toEqual(pageTitle);
31+
});
32+
33+
it('should display subtitle', () => {
34+
const subHeaderElement = rootWrapper.find('h2');
35+
expect(subHeaderElement.props().children).toEqual(pageSubTitle);
36+
});
37+
});
38+
});

Diff for: jest.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
verbose: true,
3+
setupFiles: ['./jest.setup.js'],
4+
snapshotSerializers: ['enzyme-to-json/serializer'],
5+
};

Diff for: jest.setup.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* eslint import/no-unassigned-import:0 */
2+
import 'raf/polyfill';
3+
4+
import Enzyme from 'enzyme';
5+
import Adapter from 'enzyme-adapter-react-16';
6+
7+
Enzyme.configure({ adapter: new Adapter() });

Diff for: package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,18 @@
5858
"babel-eslint": "^8.0.1",
5959
"babel-plugin-lodash": "^3.2.11",
6060
"cross-env": "^5.0.2",
61+
"enzyme": "^3.1.1",
62+
"enzyme-adapter-react-16": "^1.0.4",
63+
"enzyme-to-json": "^3.2.2",
6164
"eslint-config-prettier": "^2.3.0",
6265
"eslint-plugin-react": "^7.1.0",
6366
"husky": "^0.14.3",
6467
"jest": "^21.2.1",
6568
"lint-staged": "^4.0.2",
6669
"opn": "^5.1.0",
6770
"prettier": "^1.7.0",
71+
"raf": "^3.4.0",
72+
"react-test-renderer": "^16.0.0",
6873
"webpack-bundle-analyzer": "^2.8.3",
6974
"xo": "^0.18.2"
7075
},
@@ -81,5 +86,5 @@
8186
"bugs": {
8287
"url": "https://github.com/coderplex/coderplex/issues"
8388
},
84-
"homepage": "https://github.com/coderplex/coderplex#readme"
89+
"homepage": "https://coderplex.org"
8590
}

0 commit comments

Comments
 (0)