Skip to content
Snippets Groups Projects
Commit 90d57b4b authored by Jack Reed's avatar Jack Reed
Browse files

add a unit test using Enzyme for Display component

parent 41f3aa50
Branches
No related tags found
No related merge requests found
import React from 'react';
import { shallow } from 'enzyme';
import Display from '../../../src/components/Display';
describe('Display', () => {
it('renders without an error', () => {
const wrapper = shallow(<Display manifest={{}} />);
expect(wrapper.contains(<div className="Display"><pre id="exampleManifest" className="" /></div>)).toBe(true);
});
it('sets class based on manifest state', () => {
let wrapper = shallow(<Display manifest={{ isFetching: true }} />);
expect(wrapper.find('.fetching').length).toBe(1);
wrapper = shallow(<Display manifest={{ error: true }} />);
expect(wrapper.find('.error').length).toBe(1);
});
it('displays content', () => {
let wrapper = shallow(<Display manifest={{ isFetching: true }} />);
expect(wrapper.text()).toBe('');
wrapper = shallow(<Display manifest={{ error: { message: 'bad things' } }} />);
expect(wrapper.text()).toBe('bad things');
wrapper = shallow(<Display manifest={{ json: { iiif: 'manifest' } }} />);
expect(JSON.parse(wrapper.text())).toEqual({ iiif: 'manifest' });
});
});
This diff is collapsed.
// Setup Jest to mock fetch
import fetch from 'jest-fetch-mock'; // eslint-disable-line import/no-extraneous-dependencies
import Enzyme from 'enzyme'; // eslint-disable-line import/no-extraneous-dependencies
import Adapter from 'enzyme-adapter-react-16'; // eslint-disable-line import/no-extraneous-dependencies
jest.setMock('node-fetch', fetch);
global.fetch = require('jest-fetch-mock'); // eslint-disable-line import/no-extraneous-dependencies
Enzyme.configure({ adapter: new Adapter() });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment