Created
July 29, 2019 14:41
Star
You must be signed in to star a gist
Testing Utilities
This file contains 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"; | |
| export class GenericComponent extends React.Component { | |
| render() { | |
| return ( | |
| <div data-testid="generic"> | |
| <h1>Hello, World!</h1> | |
| </div> | |
| ); | |
| } | |
| } |
This file contains 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"; | |
| import { Router } from "react-router-dom"; | |
| import { render, wait } from "@testing-library/react"; | |
| import { createMemoryHistory } from "history"; | |
| export const renderWithRouter = ( | |
| ui, | |
| { route = "/", ...renderOptions } = {} | |
| ) => { | |
| const history = createMemoryHistory({ initialEntries: [route] }); | |
| const utils = render(<Router history={history}>{ui}</Router>, renderOptions); | |
| const finishLoading = () => | |
| wait(() => expect(utils.queryByText("Loading")).toBeNull()); | |
| return { | |
| ...utils, | |
| finishLoading, | |
| history | |
| }; | |
| }; |
This file contains 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 thunk from "redux-thunk"; | |
| import configureStore from "redux-mock-store"; | |
| export const makeMockStore = configureStore([thunk]); | |
| export const findByTestAttr = (wrapper, val) => { | |
| return wrapper.find(`[data-test-id="${val}"]`); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment