Skip to content

Instantly share code, notes, and snippets.

@phishy
Created December 13, 2014 22:42
Show Gist options
  • Save phishy/e135bdddeaf176bd5a71 to your computer and use it in GitHub Desktop.
Save phishy/e135bdddeaf176bd5a71 to your computer and use it in GitHub Desktop.
module.exports = {
process: function() {
Vendor.find().then(function(res){
console.log('success');
}).catch(function(err){
console.log('failure');
});
}
}
var Promise = require('bluebird');
var assert = require('assert');
var sinon = require('sinon');
require('sinon-as-promised')(Promise);
var rewire = require('rewire');
var Product = rewire('product.js');
var vendorStub = {};
Product.__set__({ Vendor: vendorStub });
describe(function(){
it('should stub Vendor even though Vendor isnt defined with var', function(done){
vendorStub.find = sinon.stub().resolves(true);
Product.process().then(function(res){
assert.ok(res);
}).catch(function(err){
done(err);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment