I need to mock client side HTTP requests. I'm using isomorphic-fetch
in the client side and I'm using mocha
and nock
for testing and mocking. All my client requests are based on relative path. Due to this I'm unable to provide host name for the nock
. Is there a work around.
Client side:
fetch('/foo') //hostname: http://localhost:8080
.then(res => res.json())
.then(data => console.log(data))
.catch(e => console.log(e))
Test suite
nock('/')
.get('/foo')
.reply(200, {data: "hello"})
This is failing as I'm not giving the proper hostname for the nock
. Am I doing something wrong?