mocking - Nightwatch Mock HTTP Requests -
i try mocking http requests nock , other libs sinonjs without success.
import nock "nock" const url = "http://localhost:8080/" const sign_in_path = "/fake/users/sign_in.json" export const signinrequest = (status, payload = {}) => { return nock(url).get(sign_in_path).reply(status, payload) }
-
import { signinrequest } "./../../utils/fakerequests" const dologin = (browser) => { return browser .url("http://localhost:8080") .waitforelementvisible('form', 1000) .setvalue('input[name=email]', 'foo@foo.com') .setvalue('input[name=password]', 'somepass') .click('button[type=submit]') .pause(500) } export default { "do login , shows error message": (browser) => { signinrequest(403) dologin(browser) .waitforelementvisible('.error', 1000) .end() } }
its possible mock http requests nightwatch?
nightwatch.js
end end testing tool - point actual uis api call live (and not mocked) maybe looking framework designed integration tests casper.js
(http://casperjs.org/) or nightmare
(https://github.com/segmentio/nightmare)
however mocking http calls in nightwatch
should doable nock
believe (if have strange use case warrants it) ensure you're nock http calls before tests (they can in before
block), eg:
module.exports = { 'test abc' : function (browser) { nock('http://example.com') .get('/users') .query({name: 'martin'}) .reply(200, {results: [{id: '123'}]}); // test stuff }, };
possible problem example mocking entire ui - nightwatch
might somehow preventing same domain being intercepted. having ui , api on different domains (or ports) might solve issue
Comments
Post a Comment