Nock: browser: support fetch

Created on 18 Nov 2015  路  28Comments  路  Source: nock/nock

Intercept the browser fetch API calls as we do now for http(s).request calls.

feature help wanted stale

Most helpful comment

+1

All 28 comments

+1

+1

+1

@danny-andrews @judikdavid @blackxored for now you can use fetch-mock

Yes I switched to fetch-mock after a bit of research :(

Sorry for ad of other solutions here. I'll definitely switch back to nock later (when it will support fetch) because I really like the API, code quality & docs

@vyorkin np at all.

I think that a good solution for everyone would be for browserify / webpack to use fetch as the HTTP client backend..

Yes, I'm also using fetch-mock with webpack, just wanted to switch back to nock.

+1

+1

Any proposals how it should work?

+1

+1

+1

+1

+1

+1

+1

I have migrated from karma to mocha + jsdom and now I'm running my web tests using that setup. Now I can use nock.

@alexpanov can you go more in depth about your setup? i've not been able to get nock to intercept relative API paths w/ isomorphic fetch + mocha.

@rublev
I used to have a PhantomJS based test suite. For purely historical reasons I used Karma with Jasmine for unit testing. Having Karma as a test runner in conjunction with PhantomJS meant my tests were executed from within a browser.
Now, however, the tests are being run with Mocha. There's no PhantomJS anymore, but there's jsdom. That means my tests are executed with node.

Does that help?

+1

+1

So if I summarize this issue, there is no way to intercept fetch networking activity without relying on an external module nor by stubbing the fetch object?

bump

See possible solution using fetch-mock in #591.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We try to do our best, but nock is maintained by volunteers and there is only so much we can do at a time. Thank you for your contributions.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue and add a reference to this one if it鈥檚 related. Thank you!

Was this page helpful?
0 / 5 - 0 ratings