Props are inputs passed to a component to control its behavior or display. They act like settings or instructions for the component.
Click to reveal answer
intermediate
How do you test if a component received the correct prop value in Cypress?
You can check the component's rendered output or attributes that depend on the prop. Cypress can also spy on functions to verify prop-driven behavior.
Click to reveal answer
beginner
What is an event in the context of UI testing?
An event is an action like a click, input, or submit that a user performs. Testing events means checking if the component reacts correctly to these actions.
Click to reveal answer
intermediate
How can Cypress test if an event handler was called when a button is clicked?
Use cy.get() to find the button, then .click() to simulate the click. Use cy.spy() or cy.stub() to watch the event handler and assert it was called.
Click to reveal answer
beginner
Why is testing props and events important in component testing?
Because props control what the component shows or does, and events are how users interact. Testing both ensures the component works as expected in real use.
Click to reveal answer
In Cypress, which command simulates a user clicking a button?
Acy.click()
Bcy.type()
Ccy.get().click()
Dcy.spy()
✗ Incorrect
You first select the element with cy.get(), then call .click() to simulate the click.
What does a cy.spy() do in event testing?
AIt watches if a function is called
BIt replaces the event handler
CIt triggers an event
DIt asserts the UI state
✗ Incorrect
cy.spy() watches a function to see if it was called during the test.
Which of these is a prop in component testing?
AA function passed to a component
BA browser event
CA CSS style
DA user click
✗ Incorrect
Props are inputs like functions or values passed into components.
Why test events in UI components?
ATo check if the UI looks correct
BTo check network requests
CTo measure performance
DTo verify user interactions trigger expected behavior
✗ Incorrect
Events represent user actions; testing them ensures the component responds properly.
Which Cypress command helps check if a prop affects the component output?
Acy.spy()
Bcy.get() with assertions
Ccy.stub()
Dcy.visit()
✗ Incorrect
cy.get() selects elements to assert their content or attributes changed by props.
Explain how you would test a button click event handler using Cypress.
Think about selecting the element, simulating the event, and verifying the response.
You got /4 concepts.
Describe why testing props is important and how you can verify them in Cypress tests.
Consider props as settings and how to check their effect.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of props testing in Cypress component tests?
easy
A. To verify that components receive and display data correctly
B. To check if the component's CSS styles are applied
C. To test if the component renders without errors
D. To measure the performance of component rendering
Solution
Step 1: Understand what props are
Props are data passed to components to control their behavior or display.
Step 2: Identify the goal of props testing
Props testing ensures the component uses and shows this data correctly.
Final Answer:
To verify that components receive and display data correctly -> Option A
Quick Check:
Props testing = verify data usage [OK]
Hint: Props testing checks data passed to components [OK]
Common Mistakes:
Confusing props testing with style or performance testing
Thinking props testing checks event handlers
Assuming props testing is about rendering errors
2. Which Cypress command is used to spy on an event handler function passed as a prop?
easy
A. cy.spy()
B. cy.stub()
C. cy.mount()
D. cy.visit()
Solution
Step 1: Recall Cypress commands for spying
cy.spy() creates a spy to watch function calls without changing behavior.
Step 2: Match command to event handler spying
Spying on event handlers uses cy.spy() to check if they were called.
A. The spy was not created correctly with cy.spy()
B. The event handler prop name is wrong
C. The assertion incorrectly uses parentheses after called
D. The button selector is incorrect
Solution
Step 1: Check spy creation and usage
Spy is created correctly with cy.spy() and passed as prop.
Step 2: Review assertion syntax
called is a property, not a function, so no parentheses should be used; parentheses cause failure.
Final Answer:
The assertion incorrectly uses parentheses after called -> Option C
Quick Check:
called is property, no () [OK]
Hint: Don't add () after called in assertions [OK]
Common Mistakes:
Using called() instead of called
Incorrect selector causing no click
Wrong prop name like onClickHandler
5. You want to test a component that receives a disabled prop and an onSubmit event handler prop. Which Cypress test approach correctly verifies that clicking the submit button calls onSubmit only when disabled is false?
hard
A. Mount component with disabled=true and spy on onSubmit; click button and assert spy called once; then mount with disabled=false and assert spy not called
B. Mount component with disabled=false and spy on onSubmit; click button and assert spy called once; then mount with disabled=true and assert spy not called on click
C. Mount component once with disabled=false and spy on onSubmit; click button twice and assert spy called twice regardless of disabled prop
D. Mount component with disabled=false without spy; click button and check UI changes only
Solution
Step 1: Test enabled state with spy
Mount with disabled=false, spy on onSubmit, click button, expect spy called once.
Step 2: Test disabled state with spy
Mount with disabled=true, click button, expect spy not called to confirm no event triggered.
Final Answer:
Mount component with disabled=false and spy on onSubmit; click button and assert spy called once; then mount with disabled=true and assert spy not called on click -> Option B
Quick Check:
Test both states with spy to confirm event firing [OK]
Hint: Test enabled and disabled states separately with spy [OK]
Common Mistakes:
Testing only one disabled state
Not using spy to check event calls
Assuming event fires regardless of disabled prop
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.