API
integration/sample_spec.js
describe('request test', function() {
it('', function() {
cy.server()
cy.route('GET','**/getUsers').as('getUsers')
cy.wait('@getUsers')
cy.get('#results').should('contain', 'user1')
})
})
Stub
integration/sample_spec.js
describe('request test', function() {
it('', function() {
cy.server()
cy.route('GET', '**/getUsers',
{data: [
{id: '1',name: 'user1'},
{id: '2',name: 'user2'}
]}).as('getUsers')
cy.wait('@getUsers')
cy.get('#results').should('contain', 'user1')
})
})
Fixtures
integration/sample_spec.js
describe('request test', function() {
it('', function() {
cy.server()
cy.route('GET', '**/getUsers', 'fixture:getUsers').as('getUsers')
cy.wait('@getUsers')
cy.get('#results').should('contain', 'user1')
})
})
fixtures/getUsers.json
{
"data": [{
"id": "1",
"name": "user1"
},
{
"id": "2",
"name": "user2"
}
]
}
階層が深くてもいい
integration/sample_spec.js
describe('request test', function() {
it('', function() {
cy.server()
cy.route('GET', '**/getUsers', 'fixture:test/getUsers').as('getUsers')
cy.wait('@getUsers')
cy.get('#results').should('contain', 'user1')
})
})
fixtures/test/getUsers.json
{
"data": [{
"id": "1",
"name": "user1"
},
{
"id": "2",
"name": "user2"
}
]
}
複数Wait
integration/sample_spec.js
cy.server()
cy.route('activities/*', 'fixture:activities').as('getActivities')
cy.route('messages/*', 'fixture:messages').as('getMessages')
cy.visit('http://localhost:8888/dashboard')
cy.wait(['@getActivities', '@getMessages'])
cy.get('h1').should('contain', 'Dashboard')