From c667bea33bff11cdd4eb6e1960db4f3cc8f7c772 Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Tue, 9 Jul 2019 00:10:56 +0200 Subject: [PATCH] test: adds unit tests for component (#92) --- src/components/Engines/Engines.test.tsx | 66 +++++++++++++++++++ .../__snapshots__/Engines.test.tsx.snap | 3 + 2 files changed, 69 insertions(+) create mode 100644 src/components/Engines/Engines.test.tsx create mode 100644 src/components/Engines/__snapshots__/Engines.test.tsx.snap diff --git a/src/components/Engines/Engines.test.tsx b/src/components/Engines/Engines.test.tsx new file mode 100644 index 0000000..3339b2e --- /dev/null +++ b/src/components/Engines/Engines.test.tsx @@ -0,0 +1,66 @@ +import React from 'react'; +import { shallow } from 'enzyme'; + +jest.mock('./img/node.png', () => ''); +jest.mock('../Install/img/npm.svg', () => ''); + +describe(' 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(); + 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(); + 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(); + expect(wrapper.html()).toEqual(''); + }); +}); diff --git a/src/components/Engines/__snapshots__/Engines.test.tsx.snap b/src/components/Engines/__snapshots__/Engines.test.tsx.snap new file mode 100644 index 0000000..f3ec735 --- /dev/null +++ b/src/components/Engines/__snapshots__/Engines.test.tsx.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` component should render the component in default state 1`] = `"

    node JS

  • >= 0.1.98

    NPM version

  • >3
"`;