1

This questions is specifically in relation to stubbing in Cypress with cy.intercept(), and writing E2E tests. I'm trying to figure out where exactly these intercept stubs get cleared.

In the Cypress documentation they use terms like "Suite" and "Test" but these aren't explicitly defined anywhere in their docs that I can find, and the more I read the more confused I'm getting.

For the Intercepts, in particular, the documentation says:

All intercepts are automatically cleared before every test. (reference)

So let's extend a small example from their documentation and say I have this:

describe('My First Test', () => {
  it('Does not do much!', () => {
    expect(true).to.equal(true)
  })

  it('Does do this though!', () => {
    expect(true).to.equal(true)
  })

  it('Is pretty great!', () => {
    expect(true).to.equal(true)
  })
})

From what I can tell actually running Cypress, the intercepts are cleared after each it(...) block - so each of those blocks is considered to be a "Test"?

Then every describe(...) would be considered a "Suite" here?

Ben
  • 5,079
  • 2
  • 20
  • 26

1 Answers1

2

A test is a call to it() and a suite is a call to describe() or context().

Cypress uses the Mocha framework, so this question applies to your question What is role of the suite function in Mocha?

describe() and suite() essentially do the same thing

Note, Cypress wraps the Mocha suite functions describe() and context() and exposes them globally, which is why you can use them directly in the spec.

Mocha also has suite() and test() functions which Cypress does not pass on, but you can access them using the Mocha global

Mocha.suite('My First Test', () => {
  Mocha.test('Does not do much!', () => {
    expect(true).to.equal(true)
  })

  Mocha.test('Does do this though!', () => {
    expect(true).to.equal(true)
  })

  Mocha.test('Is pretty great!', () => {
    expect(true).to.equal(true)
  })
})
Carpenter
  • 36
  • 3
  • That's helpful background, thanks. I had also forgotten that (in jest at least) [it is an alias of test](https://stackoverflow.com/questions/45778192/what-is-the-difference-between-it-and-test-in-jest) – Ben Apr 07 '23 at 21:22