Skip to content

Instantly share code, notes, and snippets.

@fillippeyton
Created May 19, 2020 18:22
Show Gist options
  • Save fillippeyton/90e3b31a870c2b81f59f4d32f15c66f5 to your computer and use it in GitHub Desktop.
Save fillippeyton/90e3b31a870c2b81f59f4d32f15c66f5 to your computer and use it in GitHub Desktop.
RTL setup() with default and overridable props
import { render, screen } from "@testing-library/react";
import { MyComponent } from "./MyComponent";
const defaultProps = {
size: "large",
color: "salmon",
butiful: true,
};
const setup = (overrideProps) -> {
const props = {
...defaultProps,
...overrideProps
};
return render(<MyComponent {...props} />);
};
describe("MyComponent", () => {
it("should render a butiful component", () => {
const { getByText } = setup();
expect(getByText(/I am butiful/i)).toBeInTheDocument();
});
it("should render an ugly component", () => {
const { getByText } = setup({ butiful: false });
expect(queryByText(/I am butiful/i)).not.toBeInTheDocument();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment