cypress-jest-adapter provides set of custom assertions using jest assertion style to Cypress expect command
Allow to use jest style commands to do assertion:
expect(1).toEqual(1)
besides chai assertions style of
expect(1).to.be.equal(1)
yarn add cypress-jest-adapteror
npm install --save cypress-jest-adapterAdd cypress-jest-adapter to cypress support/index.js file
import 'cypress-jest-adapter'| method | assertions |
|---|---|
| toBe | expect(sth).toBe |
| toBeCloseTo | expect(sth).toBeCloseTo |
| toBeDefined | expect(sth).toBeDefined |
| toBeFalsy | expect(sth).toBeFalsy |
| toBeGreaterThan | expect(sth).toBeGreaterThan |
| toBeGreaterThanOrEqual | expect(sth).toBeGreaterThanOrEqual |
| toBeLessThan | expect(sth).toBeLessThan |
| toBeLessThanOrEqual | expect(sth).toBeLessThanOrEqual |
| toBeInstanceOf | expect(sth).toBeInstanceOf |
| toBeNull | expect(sth).toBeNull |
| toBeTruthy | expect(sth).toBeTruthy |
| toBeUndefined | expect(sth).toBeUndefined |
| toBeNaN | expect(sth).toBeNaN |
| toContain | expect(sth).toContain |
| toContainEqual | expect(sth).toContainEqual |
| toEqual | expect(sth).toEqual |
| toHaveLength | expect(sth).toHaveLength |
| toMatch | expect(sth).toMatch |
| toMatchObject | expect(sth).toMatchObject |
| toHaveProperty | expect(sth).toHaveProperty |
| toStrictEqual | expect(sth).toStrictEqual |
| toThrow | expect(sth).toThrow |
| method | assertions |
|---|---|
| resolves | expect(sth).resolves.toBe(sth) |
| rejects | expect(sth).rejects.toThrow(error) |
| method | assertions |
|---|---|
| toHaveBeenCalled | expect(spy).toHaveBeenCalled |
| toHaveBeenCalledTimes | expect(spy).toHaveBeenCalledTimes |
| toHaveBeenCalledWith | expect(spy).toHaveBeenCalledWith |
| toHaveBeenNthCalledWith | expect(spy).toHaveBeenNthCalledWith |
| toHaveReturned | expect(spy).toHaveReturned |
| toHaveReturnedTimes | expect(spy).toHaveReturnedTimes |
| toHaveReturnedWith | expect(spy).toHaveReturnedWith |
| toHaveLastReturnedWith | expect(spy).toHaveLastReturnedWith |
| toHaveNthReturnedWith | expect(spy).toHaveNthReturnedWith |
| method | assertions |
|---|---|
| anything | expect(sth).toBe(expect.anything()) |
| any | expect(sth).toBe(expect.any()) |
| arrayContaining | expect(sth).toBe(expect.arrayContaining()) |
| objectContaining | expect(sth).toBe(expect.objectContaining()) |
| stringContaining | expect(sth).toBe(expect.stringContaining()) |
| stringMatching | expect(sth).toBe(expect.stringMatching()) |
For detailed usages, go to jest expect documentation
- jest expect package for value assertions
- cypress available chai-sinon package for mock assertions
- chai assert function to provide results to cypress