-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.js
47 lines (40 loc) · 1.55 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';
require('mocha');
var assert = require('assert');
var mixin = require('./');
describe('mixin-object', function() {
it('should throw an error when the first argument is not an object.', function() {
assert.throws(function() {
mixin();
});
});
it('should mix all objects into the first one.', function() {
var obj = {c: 'c'};
mixin(obj, {a: 'a'}, {b: 'b'});
assert.deepEqual(obj, {c: 'c', a: 'a', b: 'b'});
});
it('should return a new object when an empty object is passed.', function() {
var c = {c: 'c'};
var d = mixin({}, c, {a: 'a'}, {b: 'b'});
assert.deepEqual(c, {c: 'c'});
assert.deepEqual(d, {c: 'c', a: 'a', b: 'b'});
});
it('should mix properties onto a function.', function() {
function foo() {}
var c = {c: 'c'};
var d = mixin(foo, c, {a: 'a'}, {b: 'b'});
assert(foo.hasOwnProperty('a'));
assert(foo.hasOwnProperty('b'));
assert(foo.hasOwnProperty('c'));
});
it('should mixin all objects.', function() {
assert.deepEqual(mixin({a: 'a'}, {b: 'b'}), {a: 'a', b: 'b'});
assert.deepEqual(mixin({a: 'a'}, {b: 'b'}, {c: 'c'}), {a: 'a', b: 'b', c: 'c'});
assert.deepEqual(mixin({a: 'a'}, {b: {c: 'c'}}, {d: 'd'}), {a: 'a', b: {c: 'c'}, d: 'd'});
});
it('should create a new object.', function() {
assert.deepEqual(mixin({}, {a: 'a'}, {b: 'b'}), {a: 'a', b: 'b'});
assert.deepEqual(mixin({}, {a: 'a'}, {b: 'b'}, {c: 'c'}), {a: 'a', b: 'b', c: 'c'});
assert.deepEqual(mixin({}, {a: 'a'}, {b: {c: 'c'}}, {d: 'd'}), {a: 'a', b: {c: 'c'}, d: 'd'});
});
});