Created
July 29, 2019 14:41
-
-
Save jenniferlynparsons/fe79f5c1a7a00da44c7f53fff99c1cd7 to your computer and use it in GitHub Desktop.
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