Open sand4rt opened 3 months ago
@sand4rt I think ESLint rule and/or docs is the way to fix this, instead of arbitrarily restricting mount()
in some environments. There is always a way to introduce unmaintainable mess to the codebase š We should have some "best practices" or "pitfalls" in the documentation describing this. Let me know what you think.
I agree that there will always be ways to introduce mess, but i don't think there is any benefit of using
test.beforeEach(async ({ mount })
ortest.afterEach(async ({ mount })
in component testing though.
That's right. I just don't want us to introduce special cases like this, at least for now, until we see a lot of users bumping into this particular issue.
Some "best practices" or "pitfalls" would definitly be nice anyway. What would be the right place for this?
I guess the same test-components.md
? We have not yet figured out a way to structure component testing docs alongside e2e docs, so let's pile up more content in that large guide for now.
That's alright. I might add a "best practices" section in test-components.md
later on.
I don't think there are many people who will report this, but let's see. Any chance the feature-components
tag could be added? We can also see whether the counter is increasing here: https://github.com/search?q=beforeEach%28async+%28%7B+mount+%7D%29&type=code (43 matches ATM).
We can also see whether the counter is increasing here: https://github.com/search?q=beforeEach%28async+%28%7B+mount+%7D%29&type=code (43 matches ATM).
Thank you for the link! Looking at the usages, some of them look totally fine to me. Maybe it's not that obvious a decision, and folks should decide for themselves š
Thank you for the link! Looking at the usages, some of them look totally fine to me. Maybe it's not that obvious a decision, and folks should decide for themselves š
Some of them look fine now, but will look terrible when they evolve, especially if different props are needed for a few tests. In my opinion, it's better to provide users the right handles rather than trying to support everything in component testing. This same mistake was made during the Enzyme days and was a painfull lesson learned. Might be interesting to save a few links and set a reminder to check in after a few months :D
I totally respect that you don't want to add an special case just for component testing tho!
š Feature Request
The removal of
mount()
insidetest.beforeEach()
andtest.afterAll()
Example
This pattern:
Results in a way simpler testbase compared to:
Motivation
I've often seen that the use of
test.beforeEach
andtest.afterEach
in component testing creates an unmaintainable mess. Kent C. Dodds also discussed this in a blog post and introduced an ESLint rule to address this issue.One of the great advantages of Playwright fixtures is how they can prevent this issue, so there is no need for an ESLint rule.