forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.test.mjs
More file actions
88 lines (68 loc) · 2.19 KB
/
core.test.mjs
File metadata and controls
88 lines (68 loc) · 2.19 KB
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
81
82
83
84
85
86
87
88
import { expect } from 'chai';
import { extend } from '../../src/core/core.js';
describe('core', function () {
describe('#extend', function () {
it('combines two objects', function () {
const o1 = {
a: 'a',
b: 'b'
};
const o2 = {
c: 'c',
d: 'd'
};
const o3 = extend(o1, o2);
expect(o3.a).to.equal('a');
expect(o3.b).to.equal('b');
expect(o3.c).to.equal('c');
expect(o3.d).to.equal('d');
});
it('combines two arrays', function () {
const a1 = [1, 2, 3];
const a2 = [4, 5, 6];
const a3 = extend(a1, a2);
expect(a3.length).to.equal(a2.length);
expect(a3[0]).to.equal(a2[0]);
expect(a3[1]).to.equal(a2[1]);
expect(a3[2]).to.equal(a2[2]);
});
it('combines and object and an array', function () {
const o1 = { a: 'a' };
const a1 = [1, 2];
const o2 = extend(o1, a1);
expect(o2.a).to.equal('a');
expect(o2[0]).to.equal(1);
expect(o2[1]).to.equal(2);
});
it('deep combines two objects', function () {
const o1 = {
A: 'A'
};
const o2 = {
a: { b: 'b' },
c: [1, 2]
};
const o3 = extend(o1, o2);
expect(o3.a.b).to.equal('b');
expect(o3.c[0]).to.equal(1);
expect(o3.c[1]).to.equal(2);
expect(o3.A).to.equal('A');
});
it('deep combines two objects and does not copy references', function () {
const o1 = {
A: 'A'
};
const o2 = {
a: { b: 'b' },
c: [1, 2]
};
const o3 = extend(o1, o2);
// Change original so if o1 contains a reference test will fail
o2.a.b = 'z';
expect(o3.a.b).to.equal('b');
expect(o3.c[0]).to.equal(1);
expect(o3.c[1]).to.equal(2);
expect(o3.A).to.equal('A');
});
});
});