Skip to content

Instantly share code, notes, and snippets.

@gonzalolarrosa
Created August 2, 2018 00:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gonzalolarrosa/d32378c33fabaefc4f197be251b97ae2 to your computer and use it in GitHub Desktop.
Save gonzalolarrosa/d32378c33fabaefc4f197be251b97ae2 to your computer and use it in GitHub Desktop.
import React from 'react';
import { shallow } from 'enzyme';
import ChildComponent from '../ChildComponent';
const onSubmitSpy = jest.fn();
const onSubmit = onSubmitSpy;
const wrapper = shallow(<ChildComponent onSubmit={onSubmitSpy} />);
let container, containerButton;
describe("ChildComponent", () => {
beforeEach(() => {
container = wrapper.find("div");
containerButton = container.find(“Button”);
onSumbitSpy.mockClear();
});
it("should have a <div>", () => {
expect(container).toHaveLength(1);
});
it("should have a <div> with properly className prop", () => {
expect(container.props().className).toEqual("container");
});
it("should have a <Button>", () => {
expect(containerButton).toHaveLength(1);
});
describe("<Button> behaviour", () => {
it("should call onSubmit", () => {
expect(onSubmitSpy).not.toHaveBeenCalled();
containerButton.simulate(‘click’);
expect(onSubmitSpy).toHaveBeenCalled();
expect(onSubmitSpy).toHaveBeenCalledWith(“I’m your son”);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment