Bird
0
0

Which of the following is the correct Cypress syntax to assert that an element's font-weight is bold?

easy📝 Syntax Q3 of 15
Cypress - Assertions
Which of the following is the correct Cypress syntax to assert that an element's font-weight is bold?
Acy.get('p').should('have.css', 'font-weight', '700')
Bcy.get('p').should('have.css', 'font-weight', 'bold')
Ccy.get('p').should('have.attr', 'font-weight', 'bold')
Dcy.get('p').should('contain', 'font-weight: bold')
Step-by-Step Solution
Solution:
  1. Step 1: Understand CSS font-weight values

    CSS font-weight for bold is usually numeric '700', not the string 'bold'. Cypress returns computed styles as numeric strings.
  2. Step 2: Choose correct assertion syntax

    Using have.css with 'font-weight' and value '700' is correct.
  3. Final Answer:

    cy.get('p').should('have.css', 'font-weight', '700') -> Option A
  4. Quick Check:

    Font-weight numeric value = B [OK]
Quick Trick: Check computed CSS values; font-weight bold is '700' [OK]
Common Mistakes:
  • Using 'bold' string instead of numeric value
  • Using 'have.attr' for CSS properties
  • Checking text content instead of CSS

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes