describe("App", () => { it("renders correctly", () => { const wrapper = shallow(<App store={store} />); const component = wrapper.dive(); expect(toJson(component)).toMatchSnapshot(); // On the first run of this test, Jest will generate a snapshot file automatically. }); });
// Use a store factory test utility // import store from './configureStore' const setup = (initialState={}) => { const store = storeFactory(initialState); const wrapper = shallow(<Input store={store} />).dive().dive(); // get through the Connect/HOC to the actual Component // console.log(wrapper.debug()); return wrapper; }
it('delete header', () => { const w = shallow(<Job {...props} />); w.find('button[className="btn"]').simulate('click'); w.find('Header').dive().find('button').simulate('click'); expect(w.state('item').action.request.headers).toEqual([]); });
it('renders Link when prop to is passed in', () => { const wrapper = wrap({ to: 'test' }).dive() expect(wrapper.find('NavLink')).toHaveLength(1) })
describe('PatientHome', () => { it('renders h2', () => { const wrapper = setup().dive(); expect(wrapper.find('h2').text()).toEqual('Welcome back, RON WEASLEY'); }); })
beforeEach(() => { //use .dive() is important for redux-connected component //https://github.com/airbnb/enzyme/issues/1002#issuecomment-310796612 wrapper = shallow(<User {...props}/>).dive(); button = wrapper.find('button'); deleteUserSpy = jest.spyOn(userActions, 'deleteUser'); });
const setup = (initialState={}) => { const store = storeFactory(initialState) const wrapper = shallow(<NewWordButton store={store} />).dive(); return wrapper; }
describe('Testing Todos Component', () => { it('should render correctly', () => { const wrapper = shallow( <Todos />, // Passando store pelo contexto do React { context: { store }} ).dive(); expect(wrapper).toMatchSnapshot(); }); });
const setup = (initialState={}) => { const store = storeFactory(initialState); const wrapper = shallow(<Input store={store} />).dive(); return wrapper; }
describe("Category", () => { it("renders correctly", () => { const wrapper = shallow( <Category store={store} history={history} match={{ params: { id: 1 }, isExact: true, path: "", url: "" }} /> ); const component = wrapper.dive(); expect(toJson(component)).toMatchSnapshot(); // On the first run of this test, Jest will generate a snapshot file automatically. }); });
describe("Search", () => { it("renders correctly", () => { const wrapper = shallow( <Search store={store} history={history} match={{ params: { term: "" }, isExact: true, path: "", url: "" }} /> ); const component = wrapper.dive(); expect(toJson(component)).toMatchSnapshot(); // On the first run of this test, Jest will generate a snapshot file automatically. }); });
/** * Factory function to create a ShallowWrapper for the Input Component * @function setup * @param {object} initialState - Initial state for this setup. * @returns {ShallowWrapper} */ const setup = (initialState={}) => { const store = storeFactory(initialState); const wrapper = shallow(<Input store={store} />).dive(); return wrapper; }