-
-
Notifications
You must be signed in to change notification settings - Fork 768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sinon useFakeXMLHttpRequest() and fakeServer.create() don't work on Node.js #1049
Comments
I am not sure why you think this should work? The If you want to test browser code you need to be in a browser environment, like PhantomJS. If you want to unit test code that works in the browser by running the tests in Node then you need to have some network layer that abstract the differences between the underlying platforms, such as |
@fatso83 Node.js version 0.2 and above is listed on the Sinon.js homepage as a supported platform, so it's reasonable to expect Sinon's major features to work on Node.js. Indeed, the other features, such as spies and stub, do work on the platform out of the box. Of course Node.js doesn't have a browser's XHR, but it does have its own standard methods of making HTTP requests, and it would be great if those were supported, so Sinon could cover the same scope of testing as it does on the browser. This isn't a far-fetched spec: other libraries, such as Nock, support this exact feature. If Sinon doesn't support mocking HTTP requests and responses on Node.js the way it does on other platforms, then its support of Node.js is less than complete. If you google "sinon fakeserver node.js" you will see quite a few users stumbling on this lack of coverage. If there's no easy way to get these features to work on Node.js, then you should probably put a note in the docs saying that they're not supported, to avoid new users being confused. |
The Server API is a standalone package that says it
It does not say it supports replacing network calls with fakes on all platforms, only browsers. The home page of Sinon says this about the package
As such, the Server API is an extra utility package that complements the core functionality. For version 2 we are trying to slim down the core further - extracting mocks into its own package. Following that direction, having a I do agree with you that stuff like this could be better documented, and there have been plans to create a host of examples, but the project of restructuring the docs seems to be in limbo ATM. |
For posterity, the aforementioned http mocking library is actually Nock (not Nook): https://www.npmjs.com/package/nock |
@pjg - yeah, sorry about that. don't know how that happened, but I edited it now just in case. must have been thinking about replacing my Kindle 😝 |
What did you expect to happen?
Per the docs, I expected the following examples to work:
Basic fake request example:
Basic fake request example:
What actually happens
Both assertion fail, as if calling
sinon.useFakeXMLHttpRequest()
andsinon.fakeServer.create()
had no effect.How to reproduce
Run the two examples above on latest
Node.js
with latestSinon
installed.The text was updated successfully, but these errors were encountered: