Skip to content

Instantly share code, notes, and snippets.

@mikebridge
Created May 4, 2017 15:56
Show Gist options
  • Save mikebridge/b9bb34e9a2f60c871ab7e38e812c7c12 to your computer and use it in GitHub Desktop.
Save mikebridge/b9bb34e9a2f60c871ab7e38e812c7c12 to your computer and use it in GitHub Desktop.
Enzyme test for welcome.tsx
import * as React from "react";
import {Welcome} from "./welcome";
import {shallow} from "enzyme";
const name = "Tester;
describe("<Welcome />", () => {
it("renders a greeting from the name", () => {
const wrapper = shallow(<Welcome name={name} onClick={() => null} />);
expect(wrapper.text()).toBe(`Welcome, ${name}!`);
});
it("calls back when clicked", () => {
let clicked = false;
const onClick = () => clicked = true;
const wrapper = shallow(<Welcome name={name} onClick={onClick} />);
wrapper.find("div").simulate("click", { preventDefault: () => undefined });
expect(clicked).toEqual(true);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment