Implementation an autofix flag for throwSuggestions
ISSUES WHICH ARE QUESTIONS WILL BE CLOSED It's going to sound like a question but:
Do you have somewhere on the roadmap a feature to allow like in the example of prettier --write for writing suggestions instead of just throwing?
Can you give an example of a failure (ideally a complete, minimal, cloneable repro) that we should auto-fix?
Hey so my current case is happening on the company's source code so I can't share this and putting together a reproducible repo might be overkill so I'll provide more context first and will put together a repo if it's still unclear.
Provided the configuration of the repo uses throwSuggestions.
// setupTest.ts
beforeAll(() => {
configure({ throwSuggestions: true });
});
// MyComponent.tsx
const MyComponent = () => {
return (
<>
<form id="my-form">
<input name="firstName" id="firstName" />
</form>
<button type="submit" form="my-form" testId="test-button">Click me</button>
</>
)
};
// ButtonComponent.test.ts
test('renders a button...',()=>{
render(ButtonComponent)
expect(screen.getByTestId('test-button')).toBeInTheDocument();
});
Running the test suite would throw to suggest that getByRole('button', { name: "Click me"}) is a better selector.
I was wondering whether there'd be an option at some point to instead of throwing, we could specify an option for the suggestion to replace the actual code at fault.
Then it could be an option object or whatever you please.
// setupTest.ts
beforeAll(() => {
configure({ throwSuggestions: { throw: false, log: false, fix: true,} });
});
Resulting in running the tests again to replace by the suggestion (like eslint --fix).
For more context we have a mono repo with tons of tests, a lot of them were written by people who weren't aware of RTL philosophy, heavily relied on writing unit tests as opposed to feature behavior driven tests. Adding to that most of the components were crafted with accessibility issues and as a consequence were accessed mostly by testIds.
We're cleaning up the code base, some components have been fixed and during the migration the tests and selectors have been updated but running throwSuggestions ATM still returns 700+ legit errors. Finding ourselves in a situation where we try to payback some of the test debt, I reckoned such a feature would be great and was willing to understand its likeliness.
Hope this clarifies a bit.