diff --git a/index.js b/index.js index 767bc91..df56221 100644 --- a/index.js +++ b/index.js @@ -52,7 +52,9 @@ module.exports = (input, options) => { let ret; if (objType === 'function') { - ret = (...args) => options.excludeMain ? input(...args) : processFn(input, options)(...args); + ret = function (...args) { + return options.excludeMain ? input(...args) : processFn(input, options).apply(this, args); + }; } else { ret = Object.create(Object.getPrototypeOf(input)); } diff --git a/test.js b/test.js index 6419fff..8f89d0d 100644 --- a/test.js +++ b/test.js @@ -42,6 +42,10 @@ function FixtureClass() { } util.inherits(FixtureClass, FixtureParent); FixtureClass.prototype.method1 = fixture; +FixtureClass.prototype.method2Cb = function (cb) { + setImmediate(() => cb(null, this.instanceValue1)); +}; +FixtureClass.prototype.method2Async = m(FixtureClass.prototype.method2Cb); FixtureParent.prototype.overriddenValue1 = 4; FixtureClass.prototype.value1 = 'neo'; @@ -269,3 +273,8 @@ test('class support - options.include over options.exclude', t => { t.is(typeof pInstance.parentMethod1().then, 'function'); t.not(typeof pInstance.grandparentMethod1(() => {}).then, 'function'); }); + +test('promisify prototype function', async t => { + const instance = new FixtureClass(); + t.is(await instance.method2Async(), 72); +});