Permalink
Browse files

Allow stub to return new instance objects

  • Loading branch information...
1 parent b86cf7a commit ac62fdfc27b13fcd3fb59c0cf67609aecac3c928 @felixge committed Dec 9, 2010
Showing with 13 additions and 1 deletion.
  1. +1 −1 lib/gently/gently.js
  2. +12 −0 test/simple/test-gently.js
View
2 lib/gently/gently.js
@@ -13,7 +13,7 @@ module.exports = Gently;
Gently.prototype.stub = function(location, exportsName) {
function Stub() {
- Stub['new'].apply(this, arguments);
+ return Stub['new'].apply(this, arguments);
};
Stub['new'] = function () {};
View
12 test/simple/test-gently.js
@@ -207,6 +207,18 @@ test(function stub() {
assert.equal(newCalled, 1);
assert.equal(stub.toString(), 'require('+JSON.stringify(LOCATION)+')');
})();
+
+ (function testUseReturnValueAsInstance() {
+ var R = {};
+
+ Stub['new'] = function() {
+ return R;
+ };
+
+ var stub = new Stub();
+ assert.strictEqual(stub, R);
+
+ })();
})();
var EXPORTS_NAME = 'MyClass';

0 comments on commit ac62fdf

Please sign in to comment.