Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from "react";
- import { shallow } from "enzyme";
- import Authors from "./Authors";
- describe("Author", () => {
- let props;
- let wrapper;
- const alice = { id: 1, name: "alice" };
- const bob = { id: 2, name: "bob" };
- const authors = [alice, bob];
- const posts = [{ id: 1, title: "a post", body: "the body" }];
- beforeEach(() => {
- useEffect = jest.spyOn(React, "useEffect").mockImplementation(f => f());
- props = {
- fetchAuthors: jest.fn().mockResolvedValue(authors),
- fetchPosts: jest.fn().mockResolvedValue(posts)
- };
- wrapper = shallow(<Authors {...props} />);
- });
- describe("on start", () => {
- it("loads the authors", () => {
- expect(props.fetchAuthors).toHaveBeenCalled();
- });
- it("does not load posts", () => {
- expect(props.fetchPosts).not.toHaveBeenCalled();
- });
- it("renders the authors", () => {
- expect(wrapper.find("Author")).toHaveLength(2);
- const firstAuthor = wrapper.find("Author").first();
- expect(firstAuthor.prop("author")).toEqual(alice);
- expect(firstAuthor.prop("activeAuthor")).toEqual(null);
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement