diff --git a/src/stampit.js b/src/stampit.js index 2fc0acd..ee8db07 100644 --- a/src/stampit.js +++ b/src/stampit.js @@ -110,11 +110,7 @@ const baseStampit = compose({ return this(...args); }, - compose(...args) { - args = args.filter(isComposable) - .map(arg => isStamp(arg) ? arg : standardiseDescriptor(arg)); - return compose.apply(this || baseStampit, args); - } + compose: stampit }, allUtilities) }); @@ -123,7 +119,9 @@ const baseStampit = compose({ * @return {Stamp} */ function stampit(...args) { - return baseStampit.compose(...args); + args = args.filter(isComposable) + .map(arg => isStamp(arg) ? arg : standardiseDescriptor(arg)); + return compose.apply(this || baseStampit, args); } export default assign(stampit, diff --git a/test/import.js b/test/import.js index 6ac07de..fdaf68b 100644 --- a/test/import.js +++ b/test/import.js @@ -7,7 +7,7 @@ test('import is the same as require', (t) => { const stampit2 = require('../dist/stampit'); t.equal(stampit1, stampit2, - 'Should export same object for both ES and CommonJS'); + 'Should export same object for both ES6 and CommonJS'); t.end(); }); diff --git a/test/infected-statics.js b/test/infected-statics.js index fe8485a..0a49a0d 100644 --- a/test/infected-statics.js +++ b/test/infected-statics.js @@ -73,3 +73,32 @@ test('stampit().staticPropertyDescriptors static method', (t) => { t.end(); }); + +test('stampit() can be infected', t => { + let counter = 0; + const infectedStampit = function (...args) { + counter++; + args.push({ + staticProperties: { + compose: infectedStampit + } + }); + + return stampit.apply(this, args); + }; + + const stamp = infectedStampit({props: {a: 1}}) // 1 + .compose({deepProps: {b: 2}}) // 2 + .methods({c: 3}) // 3 + .compose( // 4 + infectedStampit({conf: {d: 4}}) // 5 + ); + + t.equal(counter, 5, 'should call infected compose 5 times'); + t.equal(stamp.compose.properties.a, 1, 'should compose properties'); + t.equal(stamp.compose.deepProperties.b, 2, 'should compose deepProperties'); + t.equal(stamp.compose.methods.c, 3, 'should compose methods'); + t.equal(stamp.compose.configuration.d, 4, 'should compose configuration'); + + t.end(); +});