forked from sinonjs/sinon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextend-test.js
80 lines (62 loc) · 1.98 KB
/
extend-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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"use strict";
var referee = require("referee");
var extend = require("../lib/sinon/extend");
var assert = referee.assert;
describe("extend", function () {
it("should return unaltered target when only one argument", function () {
var target = { hello: "world" };
extend(target);
assert.equals(target, { hello: "world" });
});
it("should copy all (own) properties into first argument, from all subsequent arguments", function () {
var target = { hello: "world" };
extend(target, { a: "a" }, { b: "b" });
assert.equals(target.hello, "world");
assert.equals(target.a, "a");
assert.equals(target.b, "b");
});
it("should copy toString method into target", function () {
var target = {
hello: "world",
toString: function () {
return "hello world";
}
};
var source = {
toString: function () {
return "hello source";
}
};
extend(target, source);
assert.same(target.toString, source.toString);
});
it("must copy the last occurring property into the target", function () {
var target = { a: 0, b: 0, c: 0, d: 0 };
var source1 = { a: 1, b: 1, c: 1 };
var source2 = { a: 2, b: 2 };
var source3 = { a: 3 };
extend(target, source1, source2, source3);
assert.equals(target.a, 3);
assert.equals(target.b, 2);
assert.equals(target.c, 1);
assert.equals(target.d, 0);
});
it("copies all properties", function () {
var object1 = {
prop1: null,
prop2: false
};
var object2 = {
prop3: "hey",
prop4: 4
};
var result = extend({}, object1, object2);
var expected = {
prop1: null,
prop2: false,
prop3: "hey",
prop4: 4
};
assert.equals(result, expected);
});
});