it('should not contain <FuelSavingsResults /> when necessary conditions are not met', () => { const fuelSavings = getFuelSavings(); const wrapper = shallow(<FuelSavingsForm onSaveClick={jest.fn()} onChange={jest.fn()} fuelSavings={fuelSavings} />); const expected = <FuelSavingsResults savings={fuelSavings.savings} />; expect(wrapper.contains(expected)).toBeFalsy(); });
it('should contain <FuelSavingsResults /> when necessary conditions are met', () => { const fuelSavings = getFuelSavings({ necessaryDataIsProvidedToCalculateSavings: true, savings: { monthly: 10, annual: 120, threeYear: 360 } }); const wrapper = shallow(<FuelSavingsForm onSaveClick={jest.fn()} onChange={jest.fn()} fuelSavings={fuelSavings} />); const expected = <FuelSavingsResults savings={fuelSavings.savings} />; expect(wrapper.contains(expected)).toBeTruthy(); });
test('fails with an JSX contain expectation', t => { var actual = shallow(<Foo/>); var child = <div className="foo"/>; t.true(actual.contains(child)); });
describe("A suite", function() { it("contains spec with an expectation", function() { expect(shallow(<Foo />).contains(<div className="foo" />)).toBe(true); }); it("contains spec with an expectation", function() { expect(shallow(<Foo />).is('.foo')).toBe(true); }); it("contains spec with an expectation", function() { expect(mount(<Foo />).find('.foo').length).toBe(1); }); });
describe('Home Screen', () => { it('contains title', () => { expect(shallow(<Home />).contains(<h1 className="header">Welcome to World! <b className="icon" /></h1>)).to.equal(true); }); it('contains spec with an expectation', () => { expect(shallow(<Home />).is('.home')).to.equal(true); }); it('contains spec with an expectation', () => { expect(mount(<Home />).find('.home').length).to.equal(1); }); });
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); });
describe('<LanguageProvider />', () => { it('should render its children', () => { const children = (<h1>Test</h1>); const renderedComponent = shallow( <LanguageProvider messages={messages} locale="en"> {children} </LanguageProvider> ); expect(renderedComponent.contains(children)).toBe(true); }); });
it('ModuleHighlightedCourse renders without error if prop course exists', () => { const props = { course: mockCourse } const wrapper = shallow(<ModuleHighlightedCourse {...props} />) expect(wrapper.find(Categories).length).toEqual(1) expect(wrapper.contains(error)).toEqual(false) })
describe('<NotFoundPage />', () => { it('should render the page message', () => { const renderedComponent = shallow( <NotFoundPage /> ); expect(renderedComponent.contains( <FormattedMessage {...messages.header} /> )).toEqual(true); }); });
describe('App - React components', function() { it('contains a div with class tripsorter', function() { expect(shallow(<App />).is('.tripsorter')).to.equal(true); }); it('contains a header component', function() { expect(shallow(<App />).contains([ <Header /> ])).to.equal(true); }); });
describe('Status', () => { test('shallow smoke test', () => { shallow(<Status />); }) test('receives initial data', () => { const data = 'unicorn table'; let wrapper = shallow(<Status data={data} />); let expected = (<div>The field has the value: "{data}"</div>); expect(wrapper.contains(expected)).toBe(true); }) })
it('renders the title message', () => { const rendered = shallow(<App />) const message = <h1>Guess Who</h1> expect(rendered.contains(message)).toEqual(true) })
it('should render error message inside searchBox', () => { const props = { error: true } const wrapper = shallow(<WeatherSearch {...props} />) expect(wrapper.find('.WeatherSearch_searchBox').contains(<div>Error trying to fetch a forecast</div>)).equal(true) })
it('renders app with welcome <h1>', () => { const app = shallow(<App />) const welcome = <h1>create-react-app-apollo-redux</h1> expect(app.contains(welcome)).toEqual(true) })