Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. import React from "react";
  2. import { shallow } from "enzyme";
  3. import Authors from "./Authors";
  4.  
  5. describe("Author", () => {
  6. let props;
  7. let wrapper;
  8.  
  9. const alice = { id: 1, name: "alice" };
  10. const bob = { id: 2, name: "bob" };
  11. const authors = [alice, bob];
  12. const posts = [{ id: 1, title: "a post", body: "the body" }];
  13.  
  14. beforeEach(() => {
  15. useEffect = jest.spyOn(React, "useEffect").mockImplementation(f => f());
  16.  
  17. props = {
  18. fetchAuthors: jest.fn().mockResolvedValue(authors),
  19. fetchPosts: jest.fn().mockResolvedValue(posts)
  20. };
  21.  
  22. wrapper = shallow(<Authors {...props} />);
  23. });
  24.  
  25. describe("on start", () => {
  26. it("loads the authors", () => {
  27. expect(props.fetchAuthors).toHaveBeenCalled();
  28. });
  29.  
  30. it("does not load posts", () => {
  31. expect(props.fetchPosts).not.toHaveBeenCalled();
  32. });
  33.  
  34. it("renders the authors", () => {
  35. expect(wrapper.find("Author")).toHaveLength(2);
  36.  
  37. const firstAuthor = wrapper.find("Author").first();
  38.  
  39. expect(firstAuthor.prop("author")).toEqual(alice);
  40. expect(firstAuthor.prop("activeAuthor")).toEqual(null);
  41. });
  42. });
  43. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement