As the title says, I'm using RTL + Jest (with Create-react-app setup).
My question is if I should be using a beforeAll in each test pre-rendering the component within that block, so each test doesn't have to re-render the component from scratch since my test suites always start from the same base component. Is there a performance improvement by doing this?
For example, is there an improvement in doing this
describe("MyComponent", () => {
beforeAll(() => {
render(<MyComponent {...props} />);
});
it("tests something", () => {
expect(something).toDoSomething();
});
it("tests something else", () => {
expect(somethingElse).toDoSomethingElse();
});
});
over this (other than being less verbose and re-writing the component rendering)?
describe("MyComponent", () => {
it("tests something", () => {
render(<MyComponent {...props} />);
expect(something).toDoSomething();
});
it("tests something else", () => {
render(<MyComponent {...props} />);
expect(somethingElse).toDoSomethingElse();
});
});
Should I be approaching my test suites differently by doing something else? Is it just a matter of personal preference?
I've read from Kent C Dodds blog this post where he mainly states it makes code less readable but doesn't talk about performance or if it has any kind of impact on the tests.