mercredi 25 février 2015

Intercept (mock) http requests on Node.js and browser

I don't know if I'm asking too much, but I want a library to intercept/mock HTTP requests in a isomorphic/progressive way (i.e. works the same on node.js and browser) for unit/behavior tests. Is there such a thing?


I'm building a client for an API and it must work both on server and browser. Nock is great but only for Node (as it doesn't work with Browserify, I tried).


I could just mock the library I'll use for requests (such as superagent or rest). That, however, would lock me in to some library and would require a major refactor of the tests.


My wish is to avoid duplication of tests and avoid the most checks for environment as possible. And to be agnostic of implementation, hence my need to mock the requests.


I'm almost considering making one myself (or at least a glue between two libraries).


Aucun commentaire:

Enregistrer un commentaire