Skip to content

Instantly share code, notes, and snippets.

@gpeal
Created August 10, 2012 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gpeal/3316473 to your computer and use it in GitHub Desktop.
Save gpeal/3316473 to your computer and use it in GitHub Desktop.
function A() {
return 'A1'+exports.B();
}
exports.A = A;
function B() {
return 'B1';
}
exports.B = B;
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'+F.H();
},
H: function() {
return 'H1';
}
}
exports.F = F;
exports.exports = exports;
console.log(F.G());
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 B1 with B2', function() {
sinon.stub(DummyModule, 'B', function() {
return 'B2';
})
should.equal(DummyModule.A(), 'A1B2');
})
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