-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.js
48 lines (47 loc) · 1.45 KB
/
tests.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
import { getObjectCopy } from './index.js';
// Make sure inherited properties can be overwritten and also be accessed in new methods.
export class TestClass {
constructor() {
this.prop0 = { propA: { propB: { propC: { propD: 'value' } } } };
this.prop1 = 1;
this.prop2 = 2;
}
doThis() {
return this.prop1 + this.prop2;
}
}
export class TestSubclass extends TestClass {
constructor() {
super(...arguments);
this.prop3 = this.doThis(); // 3
}
}
export class TestSubSubclass extends TestSubclass {
}
let original = new TestSubSubclass();
let copy = getObjectCopy(original);
// Make sure copy is instanceof the most distant parent:
if (copy instanceof TestClass)
console.log('test 1 passed');
else
console.log('test 1 FAILED');
// Make sure copy is instanceof its immediate class:
if (copy instanceof TestSubSubclass)
console.log('test 2 passed');
else
console.log('test 2 FAILED');
// Make sure the copy is not just a reference to the original:
if (copy !== original)
console.log('test 3 passed');
else
console.log('test 3 FAILED');
// Make sure it contains the inherited method:
if (copy.doThis && (copy.doThis() === copy.prop3))
console.log('test 4 passed');
else
console.log('test 4 FAILED');
// Make sure deeply nested properties are included in the copy:
if (copy.prop0.propA.propB.propC.propD === 'value')
console.log('test 5 passed');
else
console.log('test 5 FAILED');