thlorenz / proxyquireify

browserify >= v2 version of proxyquire. Mocks out browserify's require to allow stubbing out dependencies while testing.
MIT License
152 stars 24 forks source link

Either works in browser or node not both #19

Closed beckyconning closed 9 years ago

beckyconning commented 9 years ago

when i use

var proxyquire  = require('proxyquireify')(require);

my tests work fine in the browser but all fail (implementation seems to do nothing) in node

when i use

var proxyquire  = require('proxyquire');

the tests work in node but the browser fails with

TypeError: undefined is not a function

i'm using proxyquireify as a browserify plugin and am almost definitely missing something obvious. any support would be great thank you!

thlorenz commented 9 years ago

no way around this. proxyquire in node works totally different than in the browser. you could try to use the browser field to build a wrapper around them that will use the right one depending on where your tests run.

beckyconning commented 9 years ago

oh ok. i thought that might be the case. i'm sure there are lots of differences between proxyquireify and proxyquire but it still feels like a shame as there is a large usable intersection of shared behaviour (my tests work fine apart from this). thanks for the quick reply.

beckyconning commented 9 years ago

Anyone else looking for this functionality might want to try this https://github.com/bendrucker/proxyquire-universal.

You can use it with karma-bro by adding this to your karma configuration.

browserify: { debug: true, plugin: ['proxyquire-universal'] }