Created
August 10, 2012 18:23
-
-
Save gpeal/3316461 to your computer and use it in GitHub Desktop.
This file contains 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
exports.A = function() { | |
return 'A1'+exports.B(); | |
} | |
exports.B = function() { | |
return 'B1'; | |
} | |
function C() { | |
return 'C1'; | |
} | |
exports.C = C; | |
C.prototype.D = function() { | |
return 'D1'+this.E(); | |
} | |
C.prototype.E = function() { | |
return 'E1'; | |
} | |
var F = { | |
G: function() { | |
return 'G1'+exports.F.H(); | |
}, | |
H: function() { | |
return 'H1'; | |
} | |
} | |
exports.F = F; | |
exports.exports = exports; | |
console.log(F.G()); |
This file contains 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 should = require('should'); | |
var sinon = require('sinon'); | |
require('sinon-mocha').enhance(sinon); | |
var util = require('util'); | |
var DummyModule = require('../src/DummyModule'); | |
var http = require('http'); | |
describe('Dummy Module', function() { | |
it('should be able to replace B1 with B2', function() { | |
sinon.stub(DummyModule, 'B', function() { | |
return 'B2'; | |
}) | |
should.equal(DummyModule.A(), 'A1B2'); | |
}) | |
it('should be able to replace A1 with A2', function() { | |
sinon.stub(DummyModule, 'A', function() { | |
return 'A2' + this.B(); | |
}) | |
should.equal(DummyModule.A(), 'A2B1'); | |
}) | |
it('should be able to replace A1 with A2 and B1 with B2', function() { | |
sinon.stub(DummyModule, 'A', function() { | |
return 'A2'+this.B(); | |
}) | |
sinon.stub(DummyModule, 'B', function() { | |
return 'B2'; | |
}) | |
should.equal(DummyModule.A(), 'A2B2'); | |
}) | |
it('should be able to replace E1 with E2', function() { | |
sinon.stub(DummyModule.C.prototype, 'E', function() { | |
return 'E2'; | |
}); | |
var c = new DummyModule.C(); | |
should.equal(c.D(), 'D1E2'); | |
}) | |
it('should be able to replace G1 with G2', function() { | |
sinon.stub(DummyModule.F, 'G', function() { | |
return 'G2'+DummyModule.F.H(); | |
}) | |
should.equal(DummyModule.F.G(), 'G2H1'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment