Bird
0
0

Given the following code snippet, what will be the result of the test?

medium📝 Predict Output Q4 of 15
Cypress - File Operations
Given the following code snippet, what will be the result of the test?
cy.get('input[type=file]').selectFile('cypress/fixtures/document.pdf').then(() => {
  cy.get('input[type=file]').should('have.value', '')
})
AThe test will fail because selectFile does not work on file inputs
BThe test will fail because the value attribute contains the file name
CThe test will pass because file inputs do not show file names in value attribute
DThe test will throw a syntax error
Step-by-Step Solution
Solution:
  1. Step 1: Understand file input value behavior

    File input elements do not expose the selected file name in the 'value' attribute for security reasons, so it remains empty.
  2. Step 2: Analyze the assertion

    The assertion checks that the value is empty string, which is true after selecting a file.
  3. Final Answer:

    The test will pass because file inputs do not show file names in value attribute -> Option C
  4. Quick Check:

    File input value is empty after selectFile = D [OK]
Quick Trick: File input value stays empty after file selection [OK]
Common Mistakes:
  • Expecting file name in input value
  • Thinking selectFile fails on file inputs
  • Confusing syntax errors with runtime behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes