Created
August 26, 2014 18:20
-
-
Save OscarGodson/0f9d78e91415cd2e34f6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Foo = require('../foo/index.js'); | |
var someClass = new SomeClass({ | |
someMethod: function () { | |
// How do I stub this without requiring it to be set on the prototype? | |
// ex: w/o having it set on someClass.baz = Foo.bar(); | |
var baz = Foo.bar(); | |
if (baz == 'hello') { | |
return 1 | |
} | |
else { | |
return 0 | |
} | |
} | |
}); |
Note that the karma example above is relying on a key karma plugin, or at least my fork of it: https://github.com/jmreidy/karma-browserifast
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OK, if the issue is stubbing something internally required by another module, then you'll need proxyquireify, a browserify-specific version of proxyquire.
That'd let you do something like:
So now, internal to the Foo module, the require to
./someClass
will resolve to your stub. Hooray. All the power of Jest with the flexibility of Sinon - and it works in the browser too!Here's an example of not-real test code with Browserify, Mocha, Sinon running in a Karma harness: https://github.com/jmreidy/react-combobox/blob/master/test/combobox.test.js. Main code:
Presumably proxyquireify would work anywhere you're successfully packaging Browserify bundled code/tests. (So Jasmine should be fine.)