From 003f879a87a1d27d87b5ec8e870fd91f5c7519eb Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Sat, 24 Aug 2019 16:57:51 +0200 Subject: [PATCH] chore: adds unit test for version component --- src/components/Versions/Versions.test.tsx | 37 +++++++++++++++++-- .../__snapshots__/Versions.test.tsx.snap | 2 +- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/components/Versions/Versions.test.tsx b/src/components/Versions/Versions.test.tsx index a1c7f3f..f5415d8 100644 --- a/src/components/Versions/Versions.test.tsx +++ b/src/components/Versions/Versions.test.tsx @@ -1,11 +1,42 @@ import React from 'react'; import { shallow } from 'enzyme'; -import Versions from './Versions'; +describe(' component', () => { + beforeEach(() => { + jest.resetModules(); + }); -describe(' component', () => { test('should render the component in default state', () => { - const wrapper = shallow(); + const packageMeta = { + versions: { + '1.0.0': { + version: '1.0.0', + }, + '2.0.0': { + version: '2.0.0', + }, + '3.0.0': { + version: '3.0.0', + }, + }, + time: { + '1.0.0': '2016-08-26T22:36:41.762Z', + '2.0.0': '2017-08-26T22:36:41.762Z', + '3.0.0': '2018-02-07T06:43:22.801Z', + }, + 'dist-tags': { + latest: '3.0.0', + }, + }; + + jest.doMock('../../pages/version/Version', () => ({ + DetailContextConsumer: component => { + return component.children({ packageMeta }); + }, + })); + + const Version = require('./Versions').default; + const wrapper = shallow(); expect(wrapper.html()).toMatchSnapshot(); }); }); diff --git a/src/components/Versions/__snapshots__/Versions.test.tsx.snap b/src/components/Versions/__snapshots__/Versions.test.tsx.snap index 41d5671..d923c79 100644 --- a/src/components/Versions/__snapshots__/Versions.test.tsx.snap +++ b/src/components/Versions/__snapshots__/Versions.test.tsx.snap @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[` component should render the component in default state 1`] = `""`; +exports[` component should render the component in default state 1`] = `"

Current Tags

  • latest
    3.0.0

Version History

  • 3.0.0
    over 1 year ago
  • 2.0.0
    almost 2 years ago
  • 1.0.0
    almost 3 years ago
"`;