I try mocking HTTP requests with nock and other libs like sinonjs but without success.
import nock from \"nock\"
const URL = \"http://localhost:8080/\"
const S
Nightwatch.js is an end to end testing tool - so the point is that actual UIs as well as the api they call will be live (and not mocked)
So maybe you are looking for a framework designed for integration tests like casper.js (http://casperjs.org/) or nightmare (https://github.com/segmentio/nightmare)
However mocking http calls in nightwatch should be doable with nock i believe (if you have some strange use case that warrants it)
Ensure that you're nock http calls are before tests (they can even be in a before block), eg:
module.exports = {
'test abc' : function (browser) {
nock('http://example.com')
.get('/users')
.query({name: 'martin'})
.reply(200, {results: [{id: '123'}]});
// do test stuff
},
};
Possible problem with your example is that your mocking the entire UI - nightwatch might be somehow preventing the same domain from being intercepted. Having your UI and API on different domains (or ports) might solve the issue