Bird
0
0

Given this App Action method:

medium📝 Predict Output Q13 of 15
Cypress - Test Organization and Patterns
Given this App Action method:
const addItem = (name) => { cy.get('#item-input').type(name); cy.get('#add-button').click(); }

What will be the result of this test code?
addItem('Book'); cy.get('#item-list').should('contain', 'Book');
AThe test will fail because addItem does not return a value.
BThe test will pass if 'Book' appears in the item list after adding.
CThe test will throw a syntax error due to missing return statement.
DThe test will pass only if the input field has a placeholder 'Book'.
Step-by-Step Solution
Solution:
  1. Step 1: Understand what addItem does

    It types the given name into the input and clicks the add button, triggering UI update.
  2. Step 2: Analyze the assertion

    The test checks if '#item-list' contains the text 'Book', which should be true after adding.
  3. Final Answer:

    The test will pass if 'Book' appears in the item list after adding. -> Option B
  4. Quick Check:

    UI updates with added item = test passes [OK]
Quick Trick: Add item then check list contains it [OK]
Common Mistakes:
  • Assuming missing return causes failure
  • Confusing input placeholder with typed value
  • Expecting addItem to return a value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes