0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-06 22:40:26 -05:00
verdaccio/test/unit/webui/components/PackageSidebar/packageSidebar.spec.js

36 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-12-19 23:10:53 -05:00
/**
* Package Sidebar module
*/
import React from 'react';
import { mount } from 'enzyme';
import PackageSidebar from '../../../../../src/webui/components/PackageSidebar/index';
2017-12-19 23:10:53 -05:00
import { packageMeta } from '../store/packageMeta';
jest.mock('../../../../../src/webui/utils/api', () => ({
request: require('../__mocks__/api').default.request,
2017-12-19 23:10:53 -05:00
}));
console.error = jest.fn();
describe('<PackageSidebar /> component', () => {
2018-12-05 13:30:08 -05:00
test('should throw error for the required props', () => {
2017-12-19 23:10:53 -05:00
const wrapper = mount(<PackageSidebar />);
const { loadPackageData } = wrapper.instance();
2018-12-16 15:09:03 -05:00
expect(console.error).toHaveBeenCalled();
2018-12-16 15:27:20 -05:00
return loadPackageData().catch(response => {
2017-12-19 23:10:53 -05:00
expect(response).toBeUndefined();
expect(wrapper.state()).toEqual({ failed: true });
});
});
2018-12-05 13:30:08 -05:00
test('should load the packageMeta', () => {
const wrapper = mount(<PackageSidebar packageName={'verdaccio'} />);
2017-12-19 23:10:53 -05:00
const { loadPackageData } = wrapper.instance();
2018-12-16 15:27:20 -05:00
expect(wrapper.html()).toMatchSnapshot();
return loadPackageData('verdaccio').then(response => {
2017-12-19 23:10:53 -05:00
expect(wrapper.state('packageMeta')).toEqual(packageMeta);
});
});
});