App.test.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import "raf/polyfill";
  2. import React from "react";
  3. import { App, appName, titleName } from "./App";
  4. import { configure, shallow, mount } from "enzyme";
  5. import Adapter from "enzyme-adapter-react-16";
  6. // Configure Enzyme for the React version we are using.
  7. // Could be in a test setup file. Required for React 16, 15, 0.14, 0.13.
  8. configure({ adapter: new Adapter() });
  9. describe("<App />>", () => {
  10. const wrapper = shallow(<App />);
  11. it("should find its elements", () => {
  12. // There is one <p> in <App />: only one shoud be present in shallow rendering.
  13. expect(wrapper.find("p").length).toBe(1);
  14. expect(wrapper.find("p.App-intro").exists()).toBe(true);
  15. expect(wrapper.find("ul").hasClass("tyler")).toBe(true);
  16. expect(wrapper.find("ul").children().length).toBe(3);
  17. expect(wrapper.find("h1").text()).toBe("Welcome to React");
  18. });
  19. it("should find using props", () => {
  20. // "key" and "ref" could not be used that way.
  21. // CSS attribute syntax.
  22. expect(wrapper.find("[text='Some title']").length).toBe(1);
  23. // Object property selector.
  24. expect(wrapper.find({ text: "Some title" }).length).toBe(1);
  25. });
  26. // FIXME cannot make sense of video.
  27. // @see http://airbnb.io/enzyme/docs/api/ReactWrapper/find.html
  28. test.skip("should find using a constructor", () => {
  29. // expect(wrapper.find(function App() { return ... }).length).toBe(1);
  30. });
  31. it("should find using displayName", () => {
  32. const w = mount(<App />);
  33. expect(w.find(appName).length).toBe(1);
  34. expect(w.find(titleName).length).toBe(1);
  35. });
  36. });