|
1 | 1 | import React from 'react';
|
2 | 2 | import { shallow } from 'enzyme';
|
3 | 3 |
|
4 |
| -import Author from './Author'; |
5 |
| - |
6 | 4 | describe('<Author /> component', () => {
|
| 5 | + beforeEach(() => { |
| 6 | + jest.resetModules(); |
| 7 | + }); |
| 8 | + |
7 | 9 | test('should render the component in default state', () => {
|
| 10 | + const packageMeta = { |
| 11 | + latest: { |
| 12 | + name: 'verdaccio', |
| 13 | + version: '4.0.0', |
| 14 | + author: { |
| 15 | + name: 'verdaccio user', |
| 16 | + |
| 17 | + url: '', |
| 18 | + avatar: 'https://www.gravatar.com/avatar/000000', |
| 19 | + }, |
| 20 | + }, |
| 21 | + }; |
| 22 | + |
| 23 | + jest.doMock('../../pages/version/Version', () => ({ |
| 24 | + DetailContextConsumer: component => { |
| 25 | + return component.children({ packageMeta }); |
| 26 | + }, |
| 27 | + })); |
| 28 | + |
| 29 | + const Author = require('./Author').default; |
| 30 | + const wrapper = shallow(<Author />); |
| 31 | + expect(wrapper.html()).toMatchSnapshot(); |
| 32 | + }); |
| 33 | + |
| 34 | + test('should render the component when there is no author information available', () => { |
| 35 | + const packageMeta = { |
| 36 | + latest: { |
| 37 | + name: 'verdaccio', |
| 38 | + version: '4.0.0', |
| 39 | + }, |
| 40 | + }; |
| 41 | + |
| 42 | + jest.doMock('../../pages/version/Version', () => ({ |
| 43 | + DetailContextConsumer: component => { |
| 44 | + return component.children({ packageMeta }); |
| 45 | + }, |
| 46 | + })); |
| 47 | + |
| 48 | + const Author = require('./Author').default; |
| 49 | + const wrapper = shallow(<Author />); |
| 50 | + expect(wrapper.html()).toEqual(''); |
| 51 | + }); |
| 52 | + |
| 53 | + test('should render the component when there is no author email', () => { |
| 54 | + const packageMeta = { |
| 55 | + latest: { |
| 56 | + name: 'verdaccio', |
| 57 | + version: '4.0.0', |
| 58 | + author: { |
| 59 | + name: 'verdaccio user', |
| 60 | + url: '', |
| 61 | + avatar: 'https://www.gravatar.com/avatar/000000', |
| 62 | + }, |
| 63 | + }, |
| 64 | + }; |
| 65 | + |
| 66 | + jest.doMock('../../pages/version/Version', () => ({ |
| 67 | + DetailContextConsumer: component => { |
| 68 | + return component.children({ packageMeta }); |
| 69 | + }, |
| 70 | + })); |
| 71 | + |
| 72 | + const Author = require('./Author').default; |
8 | 73 | const wrapper = shallow(<Author />);
|
9 | 74 | expect(wrapper.html()).toMatchSnapshot();
|
10 | 75 | });
|
|
0 commit comments