Describe and It in Cypress

Profile picture for user devraj

The test interface of Cypress is borrowed from Mocha. Cypress has adopted Mocha's BDD Syntax which fits perfectly with unit and integration testing.

Cypress provides describe(), context(), it() and specify(); describe() provides a way to keep tests easier to read and organized.

Table of Content

  1. Cypress Describe
  2. Cypress Context vs Describe
  3. it in Cypress
  4. Cypress It vs Specify
  5. Example Describe and It
  6. Video Tutorial

Cypress Describe

describe() is basically to group our test cases. We can nest our tests in groups as deep as we deem necessary. describe() takes two arguments, the first is the name of the test group, and the second is a callback function. There can be multiple describe in same file. Also one describe can be declared inside another describe.

Cypress Context vs Describe

context() is just an alias for describe(), and behaves the same way. Check example below.

Cypress it

it() is used for an individual test case. it() takes two arguments, a string explaining what the test should do, and a callback function which contains our actual test:

Cypress It vs Specify

specify() is an alias for it(), so choose whatever terminology works best for you. Check below example.

Example Cypress Describe and It

describe('First Describe', () => {
  describe('Describe Inside Describe', () => {
    it('first test inside', () => {
    })
  })
  it('1st test', () => {

  })
  specify('2nd test', () => {
    
  })
  it('3rd test', () => {
    
  })
})
  
context('2nd suite', () => {
  it('first test', () => {

  })
  it('2nd test', () => {
    
  })
  it('3rd test', () => {
    
  })
})

with () => we are declaring call back function, A callback is a function passed as an argument to another function.