Page 1 of 2
Gamework Quiz
Consider the following React Component for an e-commerce app:
This component works correctly, but
testing it is difficult
— we'd have to spin up multiple user journey tests to cover the behavior exposed by different logical branches.
How would you make testing of this behavior easy?
*
A
It's easy already, I'd write multiple RTL tests to cover all logical branches
B
Replace IFs with a switch() to make the logic easier to read/test
C
Move the useEffect() into a custom hook and test it via RTL
D
Move business logic away from React code
Next