Created
May 19, 2020 18:22
-
-
Save fillippeyton/90e3b31a870c2b81f59f4d32f15c66f5 to your computer and use it in GitHub Desktop.
RTL setup() with default and overridable props
This file contains hidden or 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 { 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