mirror of
https://github.com/SomboChea/ui
synced 2026-01-20 01:55:56 +07:00
test: adds unit tests for <Engines /> component (#92)
This commit is contained in:
committed by
Juan Picado @jotadeveloper
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('');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user