Skip to content

Instantly share code, notes, and snippets.

@jenniferlynparsons
Created July 29, 2019 14:41
Show Gist options
  • Save jenniferlynparsons/fe79f5c1a7a00da44c7f53fff99c1cd7 to your computer and use it in GitHub Desktop.
Save jenniferlynparsons/fe79f5c1a7a00da44c7f53fff99c1cd7 to your computer and use it in GitHub Desktop.
Testing Utilities
import React from "react";
export class GenericComponent extends React.Component {
render() {
return (
<div data-testid="generic">
<h1>Hello, World!</h1>
</div>
);
}
}
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
};
};
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