Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.