Thanks to visit codestin.com
Credit goes to github.com

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

Tests framework added #98

Merged
merged 9 commits into from
Nov 10, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
},
"test": {
"presets": [
"react",
"es2015",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need of these because they are already present in next/babel preset we added below

["env", { "modules": "commonjs" }],
"next/babel"
]
Expand Down
22 changes: 22 additions & 0 deletions __tests__/__snapshots__/common-banner.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing CommonBanner of \`components/common-banner\` Check the snapshot 1`] = `
<div
className="jsx-1924801089"
>
<div
className="jsx-1924801089 root"
>
<h1
className="jsx-1924801089 headline"
/>
<h2
className="jsx-1924801089"
/>
</div>
<JSXStyle
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;}}"
styleId="1924801089"
/>
</div>
`;
38 changes: 38 additions & 0 deletions __tests__/common-banner.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react';
import { shallow } from 'enzyme';

import CommonBanner from '../components/common-banner';

describe('Testing CommonBanner of `components/common-banner`', () => {
const shallowWrapper = shallow(<CommonBanner />);

it('Check the snapshot', () => {
expect(shallowWrapper).toMatchSnapshot();
});

it('should have title tag rendered', () => {
expect(shallowWrapper.find('h1').length).toBe(1);
});

it('should have subtitle tag rendered', () => {
expect(shallowWrapper.find('h2').length).toBe(1);
});

describe('should render the props', () => {
const pageTitle = 'title of the page';
const pageSubTitle = 'Subtitle of the page';
const rootWrapper = shallow(
<CommonBanner pageTitle={pageTitle} pageSubTitle={pageSubTitle} />,
);

it('should display title', () => {
const headerElement = rootWrapper.find('.headline');
expect(headerElement.props().children).toEqual(pageTitle);
});

it('should display subtitle', () => {
const subHeaderElement = rootWrapper.find('h2');
expect(subHeaderElement.props().children).toEqual(pageSubTitle);
});
});
});
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
verbose: true,
setupFiles: ['./jest.setup.js'],
snapshotSerializers: ['enzyme-to-json/serializer'],
};
7 changes: 7 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint import/no-unassigned-import:0 */
import 'raf/polyfill';

import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

Enzyme.configure({ adapter: new Adapter() });
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,23 @@
},
"devDependencies": {
"babel-eslint": "^8.0.1",
"babel-jest": "^21.2.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need babel-jest ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed!

"babel-plugin-lodash": "^3.2.11",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need of all these devDependencies I think. since we have these in .babelrc
https://github.com/coderplex/coderplex/blob/f9d9478af33be8b32cfffaa6b4e246702ddc6da9/.babelrc#L9-L14

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah.. so the magic lies with in next.js 🤔 hm never digged into it anyways

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Author

@M-ZubairAhmed M-ZubairAhmed Nov 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@buoyantair yes the code for next/babel is here . Also before i have included them only in test environment, totally forgot production was using only one preset. my bad
@vinaypuppal yes i havent had chance to look into next/babel implementation. You can write they bunched those presents into one and packed it with next js.

"cross-env": "^5.0.2",
"enzyme": "^3.1.1",
"enzyme-adapter-react-16": "^1.0.4",
"enzyme-to-json": "^3.2.2",
"eslint-config-prettier": "^2.3.0",
"eslint-plugin-react": "^7.1.0",
"husky": "^0.14.3",
"jest": "^21.2.1",
"lint-staged": "^4.0.2",
"opn": "^5.1.0",
"prettier": "^1.7.0",
"raf": "^3.4.0",
"react-test-renderer": "^16.0.0",
"webpack-bundle-analyzer": "^2.8.3",
"xo": "^0.18.2"
},
Expand All @@ -81,5 +89,5 @@
"bugs": {
"url": "https://github.com/coderplex/coderplex/issues"
},
"homepage": "https://github.com/coderplex/coderplex#readme"
"homepage": "https://coderplex.org"
}
Loading