|
| 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 | +}); |
0 commit comments