Comparing version 0.0.1 to 0.0.2
@@ -22,2 +22,3 @@ 'use strict'; | ||
); | ||
delete mixin.constructor; | ||
return Object.assign(child, parent, { | ||
@@ -24,0 +25,0 @@ __mixin__: mixin, |
{ | ||
"name": "mixinable", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
233
test.js
@@ -9,12 +9,7 @@ 'use strict'; | ||
test('exports test', function (t) { | ||
t.equal(typeof mixin, 'function', | ||
'main export should be a function'); | ||
t.equal(typeof mixin.override, 'function', | ||
'override should be a function'); | ||
t.equal(typeof mixin.parallel, 'function', | ||
'parallel should be a function'); | ||
t.equal(typeof mixin.pipe, 'function', | ||
'pipe should be a function'); | ||
t.equal(typeof mixin.sequence, 'function', | ||
'sequence should be a function'); | ||
t.equal(typeof mixin, 'function', 'main export is a function'); | ||
t.equal(typeof mixin.override, 'function', 'override is a function'); | ||
t.equal(typeof mixin.parallel, 'function', 'parallel is a function'); | ||
t.equal(typeof mixin.pipe, 'function', 'pipe is a function'); | ||
t.equal(typeof mixin.sequence, 'function', 'sequence is a function'); | ||
t.end(); | ||
@@ -27,8 +22,5 @@ }); | ||
}); | ||
t.equal(typeof createFoo, 'function', | ||
'mixin should create a function'); | ||
t.equal(typeof createFoo.mixin, 'function', | ||
'mixin output should have mixin method'); | ||
t.equal(typeof createFoo().foo, 'function', | ||
'instance should have mixed-in method'); | ||
t.equal(typeof createFoo, 'function', 'mixin creates a function'); | ||
t.equal(typeof createFoo.mixin, 'function', 'mixinable has mixin method'); | ||
t.equal(typeof createFoo().foo, 'function', 'instance has mixed-in method'); | ||
t.end(); | ||
@@ -38,13 +30,7 @@ }); | ||
test('functional inheritance test', function (t) { | ||
var createFoo = mixin({ | ||
foo: function () {} | ||
}); | ||
var createBar = createFoo.mixin({ | ||
bar: function () {} | ||
}); | ||
var createFoo = mixin(); | ||
var createBar = createFoo.mixin(); | ||
var bar = createBar(); | ||
t.ok(bar instanceof createBar, | ||
'instance inherits from constructor'); | ||
t.ok(bar instanceof createFoo, | ||
'instance inherits from parent constructor'); | ||
t.ok(bar instanceof createBar, 'instance inherits from constructor'); | ||
t.ok(bar instanceof createFoo, 'instance inherits from parent constructor'); | ||
t.end(); | ||
@@ -54,13 +40,7 @@ }); | ||
test('object inheritance test', function (t) { | ||
var Foo = mixin({ | ||
foo: function () {} | ||
}); | ||
var Bar = Foo.mixin({ | ||
bar: function () {} | ||
}); | ||
var Foo = mixin(); | ||
var Bar = Foo.mixin(); | ||
var bar = new Bar(); | ||
t.ok(bar instanceof Bar, | ||
'instance inherits from class'); | ||
t.ok(bar instanceof Foo, | ||
'instance inherits from parent class'); | ||
t.ok(bar instanceof Bar, 'instance inherits from class'); | ||
t.ok(bar instanceof Foo, 'instance inherits from parent class'); | ||
t.end(); | ||
@@ -72,3 +52,3 @@ }); | ||
test('contructor override test', function (t) { | ||
t.plan(2); | ||
t.plan(3); | ||
var expectedOptions = {}; | ||
@@ -78,4 +58,4 @@ var Foo = mixin({ | ||
t.pass('constructor function is being called'); | ||
t.equal(options, expectedOptions, | ||
'options are being passed'); | ||
t.equal(options, expectedOptions, 'options are being passed'); | ||
t.ok(this instanceof Foo, 'inheritance is set up correctly'); | ||
} | ||
@@ -88,3 +68,3 @@ }); | ||
test('override test', function (t) { | ||
t.plan(2); | ||
t.plan(4); | ||
var Foo = mixin({ | ||
@@ -100,6 +80,8 @@ foo: mixin.override(function () { | ||
foo: function () { | ||
t.pass('explicitly overriden method should be called'); | ||
t.pass('explicitly overriden method is being called'); | ||
t.ok(this instanceof createBar, 'inheritance is set up correctly'); | ||
}, | ||
bar: function () { | ||
t.pass('implicitly overriden method should be called'); | ||
t.pass('implicitly overriden method is being called'); | ||
t.ok(this instanceof createBar, 'inheritance is set up correctly'); | ||
} | ||
@@ -115,3 +97,3 @@ }); | ||
test('parallel test', function (t) { | ||
t.plan(4); | ||
t.plan(8); | ||
var expectedOptions = {}; | ||
@@ -122,4 +104,4 @@ var createFoo = mixin( | ||
function (options) { | ||
t.equal(options, expectedOptions, | ||
'1st implementation is called with options'); | ||
t.equal(options, expectedOptions, '1st is being called with options'); | ||
t.ok(this instanceof createFoo, 'inheritance is set up correctly'); | ||
} | ||
@@ -131,8 +113,8 @@ ) | ||
function (options) { | ||
t.equal(options, expectedOptions, | ||
'2nd implementation is called with options'); | ||
t.equal(options, expectedOptions, '2nd is being called with options'); | ||
t.ok(this instanceof createFoo, 'inheritance is set up correctly'); | ||
}, | ||
function (options) { | ||
t.equal(options, expectedOptions, | ||
'3rd implementation is called with options'); | ||
t.equal(options, expectedOptions, '3rd is being called with options'); | ||
t.ok(this instanceof createFoo, 'inheritance is set up correctly'); | ||
} | ||
@@ -144,4 +126,4 @@ ] | ||
foo: function (options) { | ||
t.equal(options, expectedOptions, | ||
'4th implementation is called with options'); | ||
t.equal(options, expectedOptions, '4th is being called with options'); | ||
t.ok(this instanceof createFoo, 'inheritance is set up correctly'); | ||
} | ||
@@ -153,3 +135,3 @@ }); | ||
test('async parallel test', function (t) { | ||
t.plan(6); | ||
t.plan(11); | ||
var counter = 0; | ||
@@ -161,6 +143,5 @@ var expectedOptions = {}; | ||
function (options) { | ||
t.equal(counter, 0, | ||
'1st implementation is called first'); | ||
t.equal(options, expectedOptions, | ||
'1st implementation is called with options'); | ||
t.equal(counter, 0, '1st is being called first'); | ||
t.equal(options, expectedOptions, '1st is being called with options'); | ||
t.ok(this instanceof createFoo, 'inheritance is set up correctly'); | ||
return new Promise(function (resolve) { | ||
@@ -174,6 +155,5 @@ setTimeout(function () { | ||
function (options) { | ||
t.equal(counter, 0, | ||
'2nd implementation is called without waiting'); | ||
t.equal(options, expectedOptions, | ||
'2nd implementation is called with options'); | ||
t.equal(counter, 0, '2nd is being called without waiting'); | ||
t.equal(options, expectedOptions, '2nd is being called with options'); | ||
t.ok(this instanceof createFoo, 'inheritance is set up correctly'); | ||
return new Promise(function (resolve) { | ||
@@ -188,9 +168,15 @@ setTimeout(function () { | ||
} | ||
); | ||
) | ||
.mixin({ | ||
foo: function (options) { | ||
t.equal(counter, 0, '3rd is being called without waiting'); | ||
t.equal(options, expectedOptions, '3rd is being called with options'); | ||
t.ok(this instanceof createFoo, 'inheritance is set up correctly'); | ||
return ++counter; | ||
} | ||
}); | ||
var result = createFoo().foo(expectedOptions); | ||
t.ok(result instanceof Promise, | ||
'parallel\'ed method returns a promise'); | ||
t.ok(result instanceof Promise, 'parallel\'ed method returns a promise'); | ||
result.then(function () { | ||
t.equal(counter, 2, | ||
'promise resolves after all implementations'); | ||
t.equal(counter, 3, 'promise resolves after everything else'); | ||
}) | ||
@@ -205,3 +191,3 @@ .catch(function () { | ||
test('pipe test', function (t) { | ||
t.plan(9); | ||
t.plan(13); | ||
var expectedOptions = {}; | ||
@@ -215,6 +201,5 @@ var createFoo = mixin( | ||
function (value, options) { | ||
t.equal(value, 1, | ||
'1st implementation is passed inital value'); | ||
t.equal(options, expectedOptions, | ||
'1st implementation is called with options'); | ||
t.equal(value, 1, '1st is being passed inital value'); | ||
t.equal(options, expectedOptions, '1st is being called with options'); | ||
t.ok(this instanceof createFoo, 'inheritance is set up correctly'); | ||
return this.increment(value); | ||
@@ -227,13 +212,11 @@ } | ||
function (value, options) { | ||
t.equal(value, 2, | ||
'2nd implementation is passed inital value'); | ||
t.equal(options, expectedOptions, | ||
'2nd implementation is called with options'); | ||
t.equal(value, 2, '2nd is being passed inital value'); | ||
t.equal(options, expectedOptions, '2nd is being called with options'); | ||
t.ok(this instanceof createFoo, 'inheritance is set up correctly'); | ||
return this.increment(value); | ||
}, | ||
function (value, options) { | ||
t.equal(value, 3, | ||
'3rd implementation is passed updated value'); | ||
t.equal(options, expectedOptions, | ||
'3rd implementation is called with options'); | ||
t.equal(value, 3, '3rd is being passed updated value'); | ||
t.equal(options, expectedOptions, '3rd is being called with options'); | ||
t.ok(this instanceof createFoo, 'inheritance is set up correctly'); | ||
return this.increment(value); | ||
@@ -246,6 +229,5 @@ } | ||
foo: function (value, options) { | ||
t.equal(value, 4, | ||
'4th implementation is passed resulting value'); | ||
t.equal(options, expectedOptions, | ||
'4th implementation is called with options'); | ||
t.equal(value, 4, '4th is being passed resulting value'); | ||
t.equal(options, expectedOptions, '4th is being called with options'); | ||
t.ok(this instanceof createFoo, 'inheritance is set up correctly'); | ||
return this.increment(value); | ||
@@ -256,8 +238,7 @@ } | ||
var result = foo.foo(1, expectedOptions); | ||
t.equal(result, 5, | ||
'pipe\'ed method returns final value'); | ||
t.equal(result, 5, 'pipe\'ed method returns final value'); | ||
}); | ||
test('async pipe test', function (t) { | ||
t.plan(6); | ||
t.plan(11); | ||
var expectedOptions = {}; | ||
@@ -271,6 +252,5 @@ var createFoo = mixin( | ||
function (value, options) { | ||
t.equal(value, 1, | ||
'1st implementation is passed inital value'); | ||
t.equal(options, expectedOptions, | ||
'1st implementation is called with options'); | ||
t.equal(value, 1, '1st is being passed inital value'); | ||
t.equal(options, expectedOptions, '1st is being called with options'); | ||
t.ok(this instanceof createFoo, 'inheritance is set up correctly'); | ||
return new Promise(function (resolve) { | ||
@@ -281,6 +261,5 @@ setTimeout(resolve.bind(null, this.increment(value)), 1); | ||
function (value, options) { | ||
t.equal(value, 2, | ||
'2nd implementation is passed updated value'); | ||
t.equal(options, expectedOptions, | ||
'2nd implementation is called with options'); | ||
t.equal(value, 2, '2nd is being passed updated value'); | ||
t.equal(options, expectedOptions, '2nd is being called with options'); | ||
t.ok(this instanceof createFoo, 'inheritance is set up correctly'); | ||
return new Promise(function (resolve) { | ||
@@ -292,9 +271,15 @@ setTimeout(resolve.bind(null, this.increment(value)), 1); | ||
} | ||
); | ||
) | ||
.mixin({ | ||
foo: function (value, options) { | ||
t.equal(value, 3, '3rd is being passed updated value'); | ||
t.equal(options, expectedOptions, '3rd is being called with options'); | ||
t.ok(this instanceof createFoo, 'inheritance is set up correctly'); | ||
return this.increment(value); | ||
} | ||
}); | ||
var result = createFoo().foo(1, expectedOptions); | ||
t.ok(result instanceof Promise, | ||
'pipe\'ed method returns a promise'); | ||
t.ok(result instanceof Promise, 'pipe\'ed method returns a promise'); | ||
result.then(function (value) { | ||
t.equal(value, 3, | ||
'promise resolves to final value'); | ||
t.equal(value, 4, 'promise resolves to final value'); | ||
}) | ||
@@ -309,3 +294,3 @@ .catch(function () { | ||
test('sequence test', function (t) { | ||
t.plan(8); | ||
t.plan(12); | ||
var counter = 0; | ||
@@ -317,6 +302,5 @@ var expectedOptions = {}; | ||
function (options) { | ||
t.equal(++counter, 1, | ||
'1st implementation is called first'); | ||
t.equal(options, expectedOptions, | ||
'1st implementation is called with options'); | ||
t.equal(++counter, 1, '1st is being called first'); | ||
t.equal(options, expectedOptions, '1st is being called with options'); | ||
t.ok(this instanceof createFoo, 'inheritance is set up correctly'); | ||
} | ||
@@ -328,12 +312,10 @@ ) | ||
function (options) { | ||
t.equal(++counter, 2, | ||
'2nd implementation is called second'); | ||
t.equal(options, expectedOptions, | ||
'2nd implementation is called with options'); | ||
t.equal(++counter, 2, '2nd is being called second'); | ||
t.equal(options, expectedOptions, '2nd is being called with options'); | ||
t.ok(this instanceof createFoo, 'inheritance is set up correctly'); | ||
}, | ||
function (options) { | ||
t.equal(++counter, 3, | ||
'3rd implementation is called third'); | ||
t.equal(options, expectedOptions, | ||
'3rd implementation is called with options'); | ||
t.equal(++counter, 3, '3rd is being called third'); | ||
t.equal(options, expectedOptions, '3rd is being called with options'); | ||
t.ok(this instanceof createFoo, 'inheritance is set up correctly'); | ||
} | ||
@@ -345,6 +327,5 @@ ] | ||
foo: function (options) { | ||
t.equal(++counter, 4, | ||
'4th implementation is called fourth'); | ||
t.equal(options, expectedOptions, | ||
'4th implementation is called with options'); | ||
t.equal(++counter, 4, '4th is being called fourth'); | ||
t.equal(options, expectedOptions, '4th is being called with options'); | ||
t.ok(this instanceof createFoo, 'inheritance is set up correctly'); | ||
} | ||
@@ -356,3 +337,3 @@ }); | ||
test('async sequence test', function (t) { | ||
t.plan(6); | ||
t.plan(8); | ||
var counter = 0; | ||
@@ -364,6 +345,5 @@ var expectedOptions = {}; | ||
function (options) { | ||
t.equal(counter, 0, | ||
'1st implementation is called first'); | ||
t.equal(options, expectedOptions, | ||
'1st implementation is called with options'); | ||
t.equal(counter, 0, '1st is being called first'); | ||
t.equal(options, expectedOptions, '1st is being called with options'); | ||
t.ok(this instanceof createFoo, 'inheritance is set up correctly'); | ||
return new Promise(function (resolve) { | ||
@@ -377,6 +357,5 @@ setTimeout(function () { | ||
function (options) { | ||
t.equal(counter, 1, | ||
'2nd implementation is called after waiting for first'); | ||
t.equal(options, expectedOptions, | ||
'2nd implementation is called with options'); | ||
t.equal(counter, 1, '2nd is being called after waiting for first'); | ||
t.equal(options, expectedOptions, '2nd is being called with options'); | ||
t.ok(this instanceof createFoo, 'inheritance is set up correctly'); | ||
return new Promise(function (resolve) { | ||
@@ -393,7 +372,5 @@ setTimeout(function () { | ||
var result = createFoo().foo(expectedOptions); | ||
t.ok(result instanceof Promise, | ||
'sequence\'ed method returns a promise'); | ||
t.ok(result instanceof Promise, 'sequence\'ed method returns a promise'); | ||
result.then(function () { | ||
t.equal(counter, 2, | ||
'promise resolves after all implementations'); | ||
t.equal(counter, 2, 'promise resolves after everything else'); | ||
}) | ||
@@ -400,0 +377,0 @@ .catch(function () { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64337
482