What to Test in a React App — Concept Check
Questions on What to Test in a React App. Test behaviour a user can observe, not implementation. The test that breaks when you rename a state variable was never testing anything worth protecting.
Questions in this quiz
8 questions on What to Test in a React App — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.In a React app, you refactor a component's internal state management from useState to useReducer. Which test is likely to break if not written properly?
- AA test using renderWithProviders
- BA test verifying user-visible behavior
- CA test checking state variable names directly
- DA test interacting with the component's UI
2.A developer writes a test for a React component that checks if a modal is open by querying a CSS class. What is a better approach?
- AEnsure the modal's CSS class is applied
- BVerify the modal's state variable directly
- CCheck if the modal's content is visible to the user
- DUse a snapshot test for the modal
3.You are testing a form submission in a React app. Which aspect is most important to test?
- AThat the form submits and shows a result
- BThe exact structure of the form's HTML
- CThe internal state changes of the form
- DThe CSS styling of the form
4.After a bug fix, which type of test should you prioritize to prevent regression in a React app?
- ATest CSS class application
- BTest user-visible behavior that previously failed
- CTest internal state changes
- DTest third-party library internals
5.A React component uses a custom hook with complex logic. What should you focus on when writing tests?
- AThe styling of components using the hook
- BThe hook's internal implementation details
- CThe hook's effect on user-visible behavior
- DThe exact API of the hook
6.What is a common mistake when testing React components?
- AUsing renderWithProviders
- BTesting user interactions
- CTesting conditional rendering
- DTesting internal state variables
7.A developer writes a test to ensure a prop value is rendered verbatim in a React component. Why might this be unnecessary?
- AProps are part of the component's internals
- BProps rarely change
- CVerbatim rendering is trivial
- DProps are always correct
8.Which of the following is NOT worth testing in a React app?
- AThird-party library internals
- BConditional rendering
- CUser flows
- DLogic with branches