mirror of
https://github.com/SomboChea/ui
synced 2024-11-28 00:44:30 +07:00
test: adds unit tests for <Engines /> component (#92)
This commit is contained in:
parent
39867938b6
commit
c667bea33b
66
src/components/Engines/Engines.test.tsx
Normal file
66
src/components/Engines/Engines.test.tsx
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
|
jest.mock('./img/node.png', () => '');
|
||||||
|
jest.mock('../Install/img/npm.svg', () => '');
|
||||||
|
|
||||||
|
describe('<Engines /> component', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.resetModules();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should render the component in default state', () => {
|
||||||
|
const packageMeta = {
|
||||||
|
latest: {
|
||||||
|
engines: {
|
||||||
|
node: '>= 0.1.98',
|
||||||
|
npm: '>3',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
jest.doMock('../../pages/version/Version', () => ({
|
||||||
|
DetailContextConsumer: component => {
|
||||||
|
return component.children({ packageMeta });
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
const Engines = require('./Engines').default;
|
||||||
|
const wrapper = shallow(<Engines />);
|
||||||
|
expect(wrapper.html()).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should render the component when there is no engine key in package meta', () => {
|
||||||
|
const packageMeta = {
|
||||||
|
latest: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
jest.doMock('../../pages/version/Version', () => ({
|
||||||
|
DetailContextConsumer: component => {
|
||||||
|
return component.children({ packageMeta });
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
const Engines = require('./Engines').default;
|
||||||
|
const wrapper = shallow(<Engines />);
|
||||||
|
expect(wrapper.html()).toEqual('');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should render the component when there is no keys in engine in package meta', () => {
|
||||||
|
const packageMeta = {
|
||||||
|
latest: {
|
||||||
|
engines: {},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
jest.doMock('../../pages/version/Version', () => ({
|
||||||
|
DetailContextConsumer: component => {
|
||||||
|
return component.children({ packageMeta });
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
const Engines = require('./Engines').default;
|
||||||
|
const wrapper = shallow(<Engines />);
|
||||||
|
expect(wrapper.html()).toEqual('');
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,3 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
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\\">>= 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\\">>3</span></div></li></ul></div></div>"`;
|
Loading…
Reference in New Issue
Block a user