describe('<AboutPage />', () => { it('should have a header called \'About\'', () => { const wrapper = shallow(<AboutPage />); const actual = wrapper.find('h2').text(); const expected = 'About'; expect(actual).toEqual(expected); }); it('should have a header with \'alt-header\' class', () => { const wrapper = shallow(<AboutPage />); const actual = wrapper.find('h2').prop('className'); const expected = 'alt-header'; expect(actual).toEqual(expected); }); it('should link to an unknown route path', () => { const wrapper = shallow(<AboutPage />); const actual = wrapper.findWhere(n => n.prop('to') === '/badlink').length; const expected = 1; expect(actual).toEqual(expected); }); });
it('should contain <FuelSavingsTextInput /> components', () => { const fuelSavings = getFuelSavings(); const wrapper = shallow(<FuelSavingsForm onSaveClick={jest.fn()} onChange={jest.fn()} fuelSavings={fuelSavings} />); const allInputs = wrapper.find(FuelSavingsTextInput); expect(allInputs.length).toEqual(5); expect(allInputs.at(0).props().name).toEqual('newMpg'); expect(allInputs.at(0).props().value).toEqual(fuelSavings.newMpg); expect(allInputs.at(1).props().name).toEqual('tradeMpg'); expect(allInputs.at(1).props().value).toEqual(fuelSavings.tradeMpg); expect(allInputs.at(2).props().name).toEqual('newPpg'); expect(allInputs.at(2).props().value).toEqual(fuelSavings.newPpg); expect(allInputs.at(3).props().name).toEqual('tradePpg'); expect(allInputs.at(3).props().value).toEqual(fuelSavings.tradePpg); expect(allInputs.at(4).props().name).toEqual('milesDriven'); expect(allInputs.at(4).props().value).toEqual(fuelSavings.milesDriven); });
); expect(wrapper.find(FuelSavingsForm).length).toEqual(1); });
describe('Home Component', () => { const comp = <PureHome dispatch={jest.fn()} /> // shallow snapshot it('should match snapshot', () => { const tree = shallow(comp) expect(tree).toMatchSnapshot() }) it('should show <Instagram/> loader when loading=true', () => { const wrapper = shallow(comp) wrapper.setState({ loading: true }) expect(wrapper.find('InstagramStyle').length).toBe(3) }) })
it('renders a RepoItem using Enzyme 2', () => { const wrapper = shallow( <RepoItem repo={repo} selectRepo={jest.fn()} /> ); expect(wrapper.find({style: styles.item}).length).toBe(1); expect(wrapper.contains(<Text>{repo.description}</Text>)).toBe(false); });
it('renders NavLinks to home and courses', () => { const wrapper = shallow(<Header />) expect(wrapper.find(NavLink).length).toEqual(2) expect(wrapper.find(NavLink).first().prop('to')).toEqual('/') expect(wrapper.find(NavLink).last().prop('to')).toEqual('/courses') expect(wrapper.find(Link).length).toEqual(1) })
test('sets updatedAt time', t => { const wrapper = shallow(<NumberWidget socket={mockServer} name="Test" title="Number" />); const mockDate = '12/12/1212 12:00'; wrapper.setState({ time: 2000, status: 200, updatedAt: mockDate }); t.is(wrapper.find('.widget__updatedAt').text(), mockDate); wrapper.setState({ updatedAt: undefined }); t.is(wrapper.find('.widget__updatedAt').length, 0); });
it('Will show Next button on valid email', () => { const checkbox = shallow( <Email activeStep={3} next={function(){}} startOver={function(){}} styles={{}}/> ); checkbox.find('input').simulate('keyup', {target: {value: 'konmpar@gmail.com'}}); expect(checkbox.find('.btn').length).toBe(2); });
it('renders a selected RepoItem using Enzyme 2', () => { const wrapper = shallow( <RepoItem isSelected repo={repo} selectRepo={jest.fn()} /> ); expect(wrapper.find({style: [styles.item, styles.selected]}).length).toBe(1); expect(wrapper.contains(<Text>{repo.description}</Text>)).toBe(true); });