Last active
November 18, 2018 18:33
-
-
Save dennisja/0b3b6e8f64a68c4b58199cbc3d23e807 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from "react"; | |
| // get the MockedProvider from react-apollo/test-utils | |
| import { MockedProvider } from "react-apollo/test-utils"; | |
| import { cleanup, render } from "react-testing-library"; | |
| // get the UserList component and GET_USERS_QUERY | |
| // if the UserList file is in the same direcory as a file with the file containing the tests | |
| import UsersList, { GET_USERS_QUERY } from "./UserList"; | |
| describe("UserList component", () => { | |
| afterEach(cleanup); // cleanup after each test case | |
| const request = { | |
| query: GET_USERS_QUERY | |
| }; | |
| const result = { | |
| data: { | |
| users: [ | |
| { | |
| id: "2", | |
| firstName: "john", | |
| lastName: "doe", | |
| email: "[email protected]", | |
| username: "jd" | |
| }, | |
| { | |
| id: "4", | |
| firstName: "jack", | |
| lastName: "happer", | |
| email: "[email protected]", | |
| username: "jh" | |
| } | |
| ] | |
| } | |
| }; | |
| it("should render the correct content", () => { | |
| const { getByText } = render( | |
| <MockedProvider mocks={[{ request, result }]} addTypename={false}> | |
| <UsersList /> | |
| </MockedProvider> | |
| ); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment