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); });
describe('<FontAwesome />', () => { it('should render FontAwesome', () => { const wrapper = setup(); expect(wrapper.find('FontAwesome')).to.have.length(1); expect(wrapper.find('FontAwesome').props().name).to.equal('columns'); }) })
it('clears errors when email input field is modified after error', () => { const handleClientError = jest.fn(); const wrapper = shallow(<EmailForm onClientErrorHook={handleClientError} />); expect(wrapper.find({ id: 'email' }).props().value).toBe(''); wrapper.find({ id: 'email' }).simulate('change', { target: { id: 'email', value: 'invalid@email' } }); wrapper.find('form').simulate('submit', { preventDefault: () => {} }); expect(wrapper.find({ id: 'email' }).props().error).toEqual(true); expect(wrapper.find({ id: 'email' }).props().helperText).toMatch(/valid/); expect(handleClientError).toBeCalled(); wrapper.find({ id: 'email' }).simulate('change', { target: { id: 'email', value: 'other_invalid@email' } }); expect(wrapper.find({ id: 'email' }).props().error).toEqual(false); });
it('renders correct routes', () => { const wrapper = shallow(<App />) const pathMap = wrapper.find(Route).reduce((pathMap, route) => { const routeProps = route.props() pathMap[routeProps.path] = routeProps.component return pathMap }, {}) expect(pathMap['/']).toBe(Home) expect(pathMap['/contact']).toBe(Contact) })
describe("NicknameSelectorTest", () => { it("should pass", () => { expect(true).to.be.true; }); it("should be disabled without an input", () => { const wrapper = shallow(<NicknameSelector />); const button = wrapper.find("button"); expect(button.props().disabled).to.be.true; }); });
it('renders correctly', () => { const TestComponent = connect(Test); const testFn = jest.fn(); const options = {context: {strings: {}, language: {subscribe: testFn}}}; const wrapper = shallow(<TestComponent/>, options); expect(wrapper).toMatchSnapshot(); expect(wrapper.props()).toEqual(options.context); //mock component did mount behaviour wrapper.instance().subscribe(); expect(testFn).toHaveBeenCalled(); });
describe('input', () => { it('should have onChange defined', () => { const { wrapper } = setupShallow(); chai.expect(wrapper.find('input').first().props().onChange).to.be.defined; }) it('should call saveUserInput', () => { const { saveUserInput, wrapper } = setupShallow(); wrapper.find('input').simulate('change', { target: { value: 'T' } }) chai.expect(saveUserInput.calledOnce).to.be.true; }) })
it('navigation has correct links', () => { const component = shallow(<Header />) expect(component.find('li > NavLink').at(0).props().children).toContain("Home") expect(component.find('li > NavLink').at(0).props().to).toEqual("/") expect(component.find('li > NavLink').at(1).props().children).toContain("Pictures") expect(component.find('li > NavLink').at(1).props().to).toEqual("/pictures") expect(component.find('li > NavLink').at(2).props().children).toContain("Contact") expect(component.find('li > NavLink').at(2).props().to).toEqual("/contact") })
describe('ContactManager component', () => { it('should render self and subcomponents', () => { const wrapper = shallow(<ContactManager {...props} />) const contactListProps = wrapper.find('ContactList').props() expect(wrapper.find('.contact-manager')).toHaveLength(1) expect(contactListProps).toMatchObject(props) }) })
it('should render initial state', () => { const wrapper = shallow(<Converter convertCurrency={convertCurrency} rate={0} />); expect(wrapper.find('input[name="amount"]').props().value).toBe(''); expect(wrapper.find('select.currency-select-source').props().value).toBe(''); expect(wrapper.find('select.currency-select-target').props().value).toBe(''); });
describe('<FontAwesome />', () => { it(' should have an onClick defined', () => { const { wrapper } = setupShallow(); chai.expect(wrapper.find('FontAwesome').props().onClick).to.be.defined; }) it('should call hidePopOver', () => { const { hidePopOver, wrapper } = setupShallow(); wrapper.find('FontAwesome').simulate('click'); chai.expect(hidePopOver.calledOnce).to.be.true; }) })
describe('<span />', () => { it('should have an onClick defined', () => { const { wrapper } = setupShallow(); chai.expect(wrapper.find('span').at(1).props().onClick).to.be.defined; }) it('should call closeAllModals and showPopOver', () => { const { closeAllModals, showPopOver, wrapper } = setupShallow(); wrapper.find('span').at(1).simulate('click'); chai.expect(closeAllModals.calledOnce).to.be.true; chai.expect(showPopOver.calledOnce).to.be.true; }) })
it('errors when form is submitted with invalid email', () => { const handleClientError = jest.fn(); const wrapper = shallow(<EmailForm onClientErrorHook={handleClientError} />); expect(wrapper.find({ id: 'email' }).props().value).toBe(''); wrapper.find({ id: 'email' }).simulate('change', { target: { id: 'email', value: 'invalid@email' } }); wrapper.find('form').simulate('submit', { preventDefault: () => {} }); expect(wrapper.find({ id: 'email' }).props().error).toEqual(true); expect(wrapper.find({ id: 'email' }).props().helperText).toMatch(/valid/); expect(handleClientError).toBeCalled(); });
describe('<BoardItem />', () => { it('should render BoardItem that creates a new board', () => { const wrapper = setupShallow(); expect(wrapper.find('Connect(BoardItem)')).to.have.length(1); expect(wrapper.find('Connect(BoardItem)').props().boardName).to.equal('Create new board...'); }) })
describe('<p />', () => { it(' should have an onClick defined', () => { const { wrapper } = setupShallow(); chai.expect(wrapper.find('p').props().onClick).to.be.defined; }) it('should call hidePopOver', () => { const { logoutUser, wrapper } = setupShallow(); wrapper.find('p').simulate('click'); chai.expect(logoutUser.calledOnce).to.be.true; }) })