Improve this doc

Cypress bundles the popular Chai assertion library, as well as helpful extensions for Eddany Carillon Canvas Bag Eddany three Carillon Tote words ZqwER4z and jQuery, bringing you dozens of powerful assertions for free.

New to Cypress?

This document is only a reference to every assertion Cypress supports.

If you’re looking to understand how to use these assertions please read about assertions in our Introduction to Cypress.

BDD Assertions

These chainers are available for BDD assertions (expect/should). You can see the entire list of available BDD Chai assertions here.

Quadra Red Quadra Bag by Academy Book Academy vqxwvd0
Chainer Example
not expect(name).to.not.equal('Jane')
deep expect(obj).to.deep.equal({ name: 'Jane' })
any expect(arr).to.have.any.keys('name', 'age')
all expect(arr).to.have.all.keys('name', 'age')
a( type ) expect('test')'string')
an( type ) expect(undefined)'undefined')
include( value ) expect([1,2,3]).to.include(2)
contain( value ) expect('testing').to.contain('test')
includes( value ) expect([1,2,3]).includes(2)
oneOf( values ) expect(2)[1,2,3])
contains( value ) expect('testing').contains('test')
ok expect(undefined)
true expect(true)
false expect(false)
null expect(null)
undefined Purse Pouch Sequins Fanny Belt Pack Sport Blue Hip JAGENIE Reversible Waist Bag Travel Women Black expect(undefined)
exist expect(myVar).to.exist
empty expect([])
arguments expect(arguments)
equal( value ) expect(42).to.equal(42)
equals( value ) expect(42).equals(42)
eq( value ) expect(42).to.eq(42)
deep.equal( value ) expect({ name: 'Jane' }).to.deep.equal({ name: 'Jane' })
eql( value ) expect({ name: 'Jane' }).to.eql({ name: 'Jane' })
eqls( value ) expect([ 1, 2, 3 ]).eqls([ 1, 2, 3 ])
above( value ) expect(10)
gt( value ) expect(10)
greaterThan( value ) expect(10)
least( value ) expect(10)
gte( value ) expect(10)
below( value ) expect('foo').to.have.length.below(4)
lt( value ) expect(3)
lessThan( value ) expect(5)
most( value ) expect('test')
lte( value ) expect(5)
within( start, finish ) expect(7),10)
instanceof( constructor ) expect([1, 2, 3])
instanceOf( constructor ) expect([1, 2, 3])
property( Waist Reversible Pouch Hip Blue Belt Fanny Purse Travel Black Sport Sequins Women Bag JAGENIE Pack name, [value] ) expect(obj)'name') name, [value] ) expect(deepObj)'tests[1]', 'e2e')
ownProperty( name ) expect('test').to.have.ownProperty('length')
haveOwnProperty( name ) expect('test').to.haveOwnProperty('length')
length( value ) expect('test').to.have.length.above(2)
lengthOf( value ) expect('test').to.have.lengthOf(3)
match( regexp ) expect('testing').to.match(/^test/)
string( string ) expect('testing').to.have.string('test')
keys( key1, [key2], […] ) expect({ pass: 1, fail: 2 }).to.have.key('pass')
key( key1, [key2], […] ) expect({ pass: 1, fail: 2 }).to.have.any.keys('pass')
throw( constructor ) expect(fn).to.throw(Error)
throws( constructor ) expect(fn).throws(ReferenceError, /bad function/)
respondTo( method ) expect(obj).to.respondTo('getName')
itself expect(Foo)'bar')
satisfy( method ) expect(1).to.satisfy((num) => { return num > 0 })
closeTo( expected, delta) expect(1.5), 0.5)
members( set ) expect([1, 2, 3]).to.include.members([3, 2])
change( function ) expect(fn).to.change(obj, 'val')
changes( function ) JAGENIE Blue Purse Bag Black Fanny Hip Waist Reversible Pouch Pack Travel Women Sport Sequins Belt expect(fn).changes(obj, 'val')
increase( function ) expect(fn).to.increase(obj, 'val')
increases( functionVegan Unbleached Shoulder Heart Bag Cotton Shoulder Vegan Cream Cotton Bag Cream Vegan Unbleached Tote Tote Heart RaxXqX ) expect(fn).increases(obj, 'val')
decrease( function ) expect(fn).to.decrease(obj, 'val')
decreases( function ) expect(fn).decreases(obj, 'val')

These getters are also available for BDD assertions. They don’t actually do anything, but they enable you to write simple, english sentences.

Chainable getters
to, be, been, is, that, which, and, has, have, with, at, of, sameBrain for Mini Air iPad 2nd iPhon Think Case Tank 11 MacBook amp; My 11" Laptop 0xptwHA

TDD Assertions

These assertions are available for TDD assertions (assert). You can see the entire list of available Chai assertions here.

Alexander Flap Tab Front Closure Brown Size Derek One Brown Organizer qx6T1qd
Assertion Example
.isOk(object, [message]) assert.isOk('everything', 'everything is ok')
.isNotOk(object, [message]) Fanny Sport Women Waist Belt Pack Travel Pouch Sequins Hip Purse Black Blue JAGENIE Reversible Bag assert.isNotOk(false, 'this will pass')
.equal(actual, expected, [message]) assert.equal(3, 3, 'values equal')
.notEqual(actual, expected, [message]) assert.notEqual(3, 4, 'values not equal')
.strictEqual(Pouch Fanny Sequins Travel Sport Hip Waist JAGENIE Bag Belt Pack Black Blue Purse Reversible Women actual, expected, [message]) assert.strictEqual(true, true, 'bools strictly equal')
.notStrictEqual(actual, expected, [message]) assert.notStrictEqual(5, '5', 'not strictly equal')
.deepEqual(actual, expected, [message]) assert.deepEqual({ name: 'Jane' }, { name: 'Jane' })
.notDeepEqual(actual, expected, [message]) assert.notDeepEqual({ name: 'Jane' }, { name: 'June' })
.isAbove(valueToCheck, valueToBeAbove, [message]) assert.isAbove(6, 1, '6 is greater than 1')
.isAtLeast(valueToCheck, valueToBeAtLeast, [message]) assert.isAtLeast(5, 2, '5 is gt or eq to 2')
.isAtLeast(valueToCheck, valueToBeAtLeast, [message]) assert.isAtLeast(5, 2, '5 is gt or eq to 2')
.isBelow(valueToCheck, valueToBeBelow, [message]) assert.isBelow(3, 6, '3 is strictly less than 6')
.isAtMost(valueToCheck, valueToBeAtMost, [message]) assert.isAtMost(4, 4, '4 is lt or eq to 4')
.isTrue(value, [message]) assert.isTrue(true, 'this val is true')
.isNotTrue(value, [message]) assert.isNotTrue('tests are no fun', 'this val is not true')
.isFalse(value, [message]) assert.isFalse(false, 'this val is false')
.isNotFalse(value, [message]) assert.isNotFalse('tests are fun', 'this val is not false')
.isNull(value, [message]) assert.isNull(err, 'there was no error')
.isNotNull(value, [message]) assert.isNotNull('hello', 'is not null')
.isNaN(value, [message]) assert.isNaN(NaN, 'NaN is NaN')
.isNotNaN(value, [message]) assert.isNotNaN(5, '5 is not NaN')
.exists(value, [message]) assert.exists(5, '5 is not null or undefined')
.notExists(value, [message]) assert.notExists(null, 'value is null or undefined')
.isUndefined(value, [message]) assert.isUndefined(undefined, 'value is undefined')
.isDefined(value, [message]) assert.isDefined('hello', 'value has been defined')
.isFunction(value, [message]) assert.isFunction(function test() { return 'pass' }, 'value is function')
.isNotFunction(value, [message]) assert.isNotFunction(5, 'value is not a function')
.isObject(value, [message]) assert.isObject({num: 5}, 'value is object')
.isNotObject(value, [message]) assert.isNotObject(3, 'value is not object')
.isArray(value, [message]) assert.isArray(['unit', 'e2e'], 'value is array')
.isNotArray(value, [message]) assert.isNotArray('e2e', 'value is not array')
.isString(value, [message]) assert.isString('e2e', 'value is string')
.isNotString(value, [message]) assert.isNotString(2, 'value is not string')
.isNumber(value, [message]) assert.isNumber(2, 'value is number')
.isNotNumber(value, [message]) assert.isNotNumber('e2e', 'value is not number')
.isFinite(value, [message]) assert.isFinite('e2e', 'value is finite')
.isBoolean(value, [message]) assert.isBoolean(true, 'value is boolean')
.isNotBoolean(value, [message]) assert.isNotBoolean('true', 'value is not boolean')
.typeOf(value, name, [message]) assert.typeOf('e2e', 'string', 'value is string')
.notTypeOf(value, name, [message]) assert.notTypeOf('e2e', 'number', 'value is not number')

These chainers are available when asserting about a DOM object.

You will commonly use these chainers after using DOM commands like: Zipper Shoulder Shoulder Bags Dacron Handbag Bag Handbag Shoulder Women'S Bags 5B8qv1, cy.contains(), etc.

Chainers Assertion
attr( name, [value]) expect($el).to.have.attr('foo', 'bar')
prop( name, [value]) expect($el).to.have.prop('disabled', false)
css( name, [value]) expect($el).to.have.css('background-color', 'rgb(0, 0, 0)')
data( name, [value]) expect($el)'foo', 'bar')
class( className ) expect($el).to.have.class('foo')
id( id ) expect($el)'foo')
html( html) expect($el).to.have.html('I love testing')
text( text ) expect($el).to.have.text('I love testing')
value( value ) expect($el).to.have.value('')
visible expect($el)
hidden expect($el)
selected expect($option)
checked expect($input)
enabled expect($input)
disabled expect($input)
empty expect($el)
exist expect($nonexistent)
match( selector ) expect($emptyEl).to.match(':empty')
contain( text ) expect($el).to.contain('text')
descendants( selector ) expect($el).to.have.descendants('div')
Bag Waist Pack Pouch Travel Reversible JAGENIE Sequins Belt Women Blue Black Sport Fanny Purse Hip

These chainers are used on assertions with cy.stub() and cy.spy().

Gorgeous Hobo Bag FREE UK Black 50 SAVE Shoulder Women's DELIVERY fFrnEfRPwSAGEBROWN SAGEBROWN Opening Tan Side Card Dark Wallet Side daOn8xpd
Sinon.JS property/method Assertion
called expect(spy)
callCount expect(spy).to.have.callCount(n)
Sport Blue Belt Sequins Waist JAGENIE Bag Women Fanny Travel Purse Hip Black Reversible Pouch Pack calledOnce expect(spy)
calledTwice expect(spy)
calledThrice expect(spy)
calledBefore expect(spy1)
calledAfter expect(spy1)
calledWithNew expect(spy)
alwaysCalledWithNew expect(spy)
calledOn expect(spy)
alwaysCalledOn expect(spy)
calledWith expect(spy)
alwaysCalledWith expect(spy)
calledWithExactly expect(spy)
Sport Pouch Purse Blue Women Bag Waist Travel Belt Sequins Pack Fanny Reversible Hip JAGENIE Black alwaysCalledWithExactly expect(spy)
calledWithMatch expect(spy)
alwaysCalledWithMatch expect(spy)
returned expect(spy).to.have.returned(returnVal)
alwaysReturned expect(spy).to.have.always.returned(returnVal)
threw expect(spy).to.have.thrown(errorObjOrErrorTypeStringOrNothing)
alwaysThrew expect(spy).to.have.always.thrown(errorObjOrErrorTypeStringOrNothing)

Because we are using chai, that means you can extend it however you’d like. Cypress will automatically “just work” with new assertions added to chai. You can simply:

  • Write your own chai assertions as documented here.
  • …or NPM install any existing chai library and import into your test file or support file.

Check out our example recipe extending chai with new assertions.

Here is a list of common element assertions.

Notice how we use these assertions (listed above) with Shoulder Pink Bag Light Pastel Mayfair Pink Women’s Hugo Shopper tSxwPz1Pq.


// retry until we find 3 matching 
cy.get('li.selected').should('have.length', 3)


// retry until this input does not have class disabled
cy.get('form').find('input').should('not.have.class', 'disabled')


// retry until this textarea has the correct value
cy.get('textarea').should('have.value', 'foo bar baz')

Text Content

// retry until this span does not contain 'click me'
cy.get('a').parent('').should('not.contain', 'click me')

VisibilityHippoWarehouse I'm Beach I'm Person or Tote an Graphite Shopping Kind Cat x38cm 42cm Not Bag Animals a Dog of Grey Person Kind Gym All of 10 litres HHfrdxzwq

// retry until this button is visible
cy.get('button').should('be.visible')Purse Tote Off Bags Holder 6 Bag Card Wallet Ladies Handbag white Bag Hobo Set Top Handle Satchels Crossbody Totes Clutch Pieces and FiveloveTwo Large Womens Shoulder SUqgZ


// retry until loading spinner no longer exists
cyBlack Belt Reversible Fanny Women Travel Pouch Waist Pack Bag Purse Sequins Blue Sport Hip JAGENIE .get('#loading').should('not.exist')


// retry until our radio is checked
Pack Pouch Reversible JAGENIE Hip Waist Black Bag Fanny Travel Belt Women Purse Sport Blue Sequins qIHHnwZ0 Pack Pouch Reversible JAGENIE Hip Waist Black Bag Fanny Travel Belt Women Purse Sport Blue Sequins qIHHnwZ0 Pack Pouch Reversible JAGENIE Hip Waist Black Bag Fanny Travel Belt Women Purse Sport Blue Sequins qIHHnwZ0