Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is a "Test" in Cypress as far as when intercepts are cleared?

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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)
  })
})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading