Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var moduleStubs = {};
- var originalJsLoader = require.extensions['.js'];
- var stubOnModule = function(module) {
- var path = require.resolve(module);
- var stub = sinon.stub();
- moduleStubs[path] = stub;
- delete require.cache[path];
- return stub;
- };
- require.extensions['.js'] = function (obj, path) {
- if (moduleStubs[path])
- obj.exports = moduleStubs[path];
- else
- return originalJsLoader(obj, path);
- };
- afterEach(function() {
- for (var path in moduleStubs) {
- delete moduleStubs[path];
- }
- });
Add Comment
Please, Sign In to add comment