Skip to content

Commit c667bea

Browse files
ayusharmajuanpicado
authored andcommitted
test: adds unit tests for <Engines /> component (conventional-changelog#92)
1 parent 3986793 commit c667bea

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import React from 'react';
2+
import { shallow } from 'enzyme';
3+
4+
jest.mock('./img/node.png', () => '');
5+
jest.mock('../Install/img/npm.svg', () => '');
6+
7+
describe('<Engines /> component', () => {
8+
beforeEach(() => {
9+
jest.resetModules();
10+
});
11+
12+
test('should render the component in default state', () => {
13+
const packageMeta = {
14+
latest: {
15+
engines: {
16+
node: '>= 0.1.98',
17+
npm: '>3',
18+
},
19+
},
20+
};
21+
22+
jest.doMock('../../pages/version/Version', () => ({
23+
DetailContextConsumer: component => {
24+
return component.children({ packageMeta });
25+
},
26+
}));
27+
28+
const Engines = require('./Engines').default;
29+
const wrapper = shallow(<Engines />);
30+
expect(wrapper.html()).toMatchSnapshot();
31+
});
32+
33+
test('should render the component when there is no engine key in package meta', () => {
34+
const packageMeta = {
35+
latest: {},
36+
};
37+
38+
jest.doMock('../../pages/version/Version', () => ({
39+
DetailContextConsumer: component => {
40+
return component.children({ packageMeta });
41+
},
42+
}));
43+
44+
const Engines = require('./Engines').default;
45+
const wrapper = shallow(<Engines />);
46+
expect(wrapper.html()).toEqual('');
47+
});
48+
49+
test('should render the component when there is no keys in engine in package meta', () => {
50+
const packageMeta = {
51+
latest: {
52+
engines: {},
53+
},
54+
};
55+
56+
jest.doMock('../../pages/version/Version', () => ({
57+
DetailContextConsumer: component => {
58+
return component.children({ packageMeta });
59+
},
60+
}));
61+
62+
const Engines = require('./Engines').default;
63+
const wrapper = shallow(<Engines />);
64+
expect(wrapper.html()).toEqual('');
65+
});
66+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`<Engines /> component should render the component in default state 1`] = `"<div class=\\"MuiGrid-container-1\\"><div class=\\"MuiGrid-item-2 MuiGrid-grid-xs-6-35\\"><ul class=\\"MuiList-root-98 MuiList-padding-99 MuiList-subheader-101\\"><h3 class=\\"MuiTypography-root-102 MuiTypography-subheading-109 css-hyrz44 et66bt70\\">node JS</h3><li class=\\"MuiListItem-root-138 MuiListItem-default-141 MuiListItem-gutters-146 css-dt93b2 et66bt71\\"><div class=\\"MuiAvatar-root-150 MuiAvatar-colorDefault-151\\"></div><div class=\\"MuiListItemText-root-153\\"><span class=\\"MuiTypography-root-102 MuiTypography-subheading-109 MuiListItemText-primary-156\\">&gt;= 0.1.98</span></div></li></ul></div><div class=\\"MuiGrid-item-2 MuiGrid-grid-xs-6-35\\"><ul class=\\"MuiList-root-98 MuiList-padding-99 MuiList-subheader-101\\"><h3 class=\\"MuiTypography-root-102 MuiTypography-subheading-109 css-hyrz44 et66bt70\\">NPM version</h3><li class=\\"MuiListItem-root-138 MuiListItem-default-141 MuiListItem-gutters-146 css-dt93b2 et66bt71\\"><div class=\\"MuiAvatar-root-150 MuiAvatar-colorDefault-151\\"></div><div class=\\"MuiListItemText-root-153\\"><span class=\\"MuiTypography-root-102 MuiTypography-subheading-109 MuiListItemText-primary-156\\">&gt;3</span></div></li></ul></div></div>"`;

0 commit comments

Comments
 (0)