nock: Does not work with browserify
Nock expects http.ClientRequest to be defined; the http module that browserify supplies does not use this internal object. Since ClientRequest is an internal object not typically used in an application space, I’m filing this as a bug – just because you’re CommonJS, doesn’t mean you’re running on node 😃
The error that exposes this issue:
PhantomJS 1.9.2 (Linux) ERROR
TypeError: 'undefined' is not an object (evaluating 'superCtor.prototype')
at /tmp/karma-browerify.js:1740
PhantomJS 1.9.2 (Linux): Executed 0 of 0 ERROR (12.249 secs / 0 secs)
I’ve traced it down to line 161 of intercept.js.
I understand if you consider nock to be just-for-node, and that extending nock to support mocking out browserify’s http shim might be out of scope for the project. But it should probably be noted in the README.md that browserify is explicitly not supported (and, to be nice, suggest an alternative).
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 50 (11 by maintainers)
Commits related to this issue
- Fix browserify compatibility Fixes #150 — committed to enykeev/nock by deleted user 10 years ago
- make nock work on browserify. fixes #150 — committed to nock/nock by pgte 9 years ago
- no presumption we have fs because of browserify. another attempt at trying to fix #150 — committed to nock/nock by pgte 9 years ago
@JuHwon @miazoom @choonkending I’ve been trying to test my
axiosclients withkarmaandphantomjsusingnockbut had 0 success. The client is still hitting the real server. Anyone got around it?@miazoom @choonkending having the same issue while following the redux test examples from the doc. Did you solve this?
Not sure if this will break something else, but in Karma.conf you can try this to get around
fsissues:@miazoom why not try “fetch-mock”
instead of
I made https://github.com/algolia/faux-jax/ which is a mock around XHR/XDR with feature detection to support and mimick as many browsers implementations as possible.
Would it be trivial to add it to nock? Let me know.
Also, this issue was resolved, does it means we can mock ajax requests in the browser using nock? Does it supports XDomainRequests? Does it implements the xhr spec?