respondOnce

Only respond once with given overwrite. You can call respondOnce multiple consecutive times and it will start with the respond you defined last. If you only use respondOnce and the resource is called more times a mock has been defined than it defaults back to the original resource.

Usage#
mock.respondOnce(overwrites, { header, statusCode, fetchResponse })
Parameters#
NameTypeDetails
overwritesMockOverwritepayload to overwrite the response
params
optional
MockResponseParamsadditional respond parameters to overwrite
params.header
optional
Objectoverwrite specific headers
params.statusCode
optional
Numberoverwrite response status code
params.fetchResponse
optional
Booleanfetch real response before responding with mocked data
Example#
respondOnce.js
function getToDos () {
$('#todo-list li').waitForExist()
return $$('#todo-list li').map(el => el.getText())
}
it('should demonstrate the respondOnce command', () => {
const mock = browser.mock('https://todo-backend-express-knex.herokuapp.com/', {
method: 'get'
})
mock.respondOnce([{
title: '3'
}, {
title: '2'
}, {
title: '1'
}])
mock.respondOnce([{
title: '2'
}, {
title: '1'
}])
mock.respondOnce([{
title: '1'
}])
browser.url('https://todobackend.com/client/index.html?https://todo-backend-express-knex.herokuapp.com/')
console.log(getToDos()) // outputs [ '3', '2', '1' ]
browser.url('https://todobackend.com/client/index.html?https://todo-backend-express-knex.herokuapp.com/')
console.log(getToDos()) // outputs [ '2', '1' ]
browser.url('https://todobackend.com/client/index.html?https://todo-backend-express-knex.herokuapp.com/')
console.log(getToDos()) // outputs [ '1' ]
browser.url('https://todobackend.com/client/index.html?https://todo-backend-express-knex.herokuapp.com/')
console.log(getToDos()) // outputs actual resource response
})