forked from cypress-io/cypress-example-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stubbed-api-spec.js
32 lines (26 loc) · 876 Bytes
/
stubbed-api-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/// <reference types="Cypress" />
// in this test, there is no backend for the app to hit
// @see https://github.com/cypress-io/cypress/issues/9599
describe('intercept', () => {
context('stubbed API', () => {
it('fetches mock users', () => {
cy.visit('/local-api-example')
cy.intercept('GET', '/users', {
fixture: 'users.json',
}).as('users')
cy.get('#load-users').click()
cy.wait('@users')
cy.get('.user').should('have.length', 2)
})
// see https://github.com/cypress-io/cypress/issues/9602
it('fetches mock users even if the request uses headers', () => {
cy.visit('/local-api-example')
cy.intercept('/users', {
fixture: 'users.json',
}).as('users')
cy.get('#load-users-headers').click()
cy.wait('@users')
cy.get('.user').should('have.length', 2)
})
})
})