0
0
Cypresstesting~5 mins

expect() for BDD assertions in Cypress - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of expect() in BDD assertions?

expect() is used to write readable tests that check if a value meets certain conditions. It helps confirm that the app behaves as expected.

Click to reveal answer
beginner
How do you check if a number is equal to 5 using expect()?

You write expect(number).to.equal(5). This asserts that the variable number should be exactly 5.

Click to reveal answer
beginner
What does expect(value).to.be.true check?

It checks that the value is exactly true. This is useful for boolean conditions.

Click to reveal answer
beginner
How can you check if a string contains a word using expect()?

Use expect(string).to.include('word'). This checks if the string has the word anywhere inside it.

Click to reveal answer
beginner
What happens if an expect() assertion fails during a test?

The test will stop and show a failure message explaining which check did not pass. This helps find bugs quickly.

Click to reveal answer
Which expect() assertion checks if a value is greater than 10?
Aexpect(value).to.be.greaterThan(10)
Bexpect(value).to.be.above(10)
Cexpect(value).to.equal(10)
Dexpect(value).to.include(10)
What does expect(array).to.have.length(3) verify?
AArray has at least 3 items
BArray is empty
CArray contains the number 3
DArray has exactly 3 items
How do you assert that a variable isActive is false?
Aexpect(isActive).to.be.false
Bexpect(isActive).to.equal(true)
Cexpect(isActive).to.be.true
Dexpect(isActive).to.include(false)
Which assertion checks if a string starts with 'Hello'?
Aexpect(str).to.have.length('Hello')
Bexpect(str).to.include('Hello')
Cexpect(str).to.startWith('Hello')
Dexpect(str).to.equal('Hello')
What is the main benefit of using expect() in tests?
ATo check if code meets expected results clearly
BTo write complex loops
CTo style the webpage
DTo create variables
Explain how expect() is used in Cypress to verify that a button is visible on the page.
Think about how you find elements and check their state.
You got /3 concepts.
    Describe the difference between expect(value).to.equal() and expect(value).to.include().
    Consider whole vs part matching.
    You got /3 concepts.