我已经使用 react 测试库触发了组件的更改,我想检查组件状态的相应更改。
是否可以检查组件的状态
最佳答案
可能是不可行的,因为这直接违反了 React-Testing-Library 的原则
Intro
The problem
You want to write maintainable tests for your React components. As a part of this goal, you want your tests to avoid including implementation details of your components and rather focus on making your tests give you the confidence for which they are intended. As part of this, you want your testbase to be maintainable in the long run so refactors of your components (changes to implementation but not functionality) don't break your tests and slow you and your team down.
This solution
The more your tests resemble the way your software is used, the more confidence they can give you.
基本上,它不关心组件的内部实现细节,例如
state
,而是它的 API,即 Prop 以及用户如何与之交互。它更像是黑盒测试。
关于javascript - 使用 react 测试库检查组件的状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61813319/