forked from emberjs/ember.js
/
copy_test.js
64 lines (55 loc) · 2.01 KB
/
copy_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
import copy from '../../lib/copy';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
moduleFor(
'Ember Copy Method',
class extends AbstractTestCase {
['@test Ember.copy null'](assert) {
let obj = { field: null };
let copied = null;
expectDeprecation(() => {
copied = copy(obj, true);
}, 'Use ember-copy addon instead of copy method and Copyable mixin.');
assert.equal(copied.field, null, 'null should still be null');
}
['@test Ember.copy date'](assert) {
let date = new Date(2014, 7, 22);
let dateCopy = null;
expectDeprecation(() => {
dateCopy = copy(date);
}, 'Use ember-copy addon instead of copy method and Copyable mixin.');
assert.equal(date.getTime(), dateCopy.getTime(), 'dates should be equivalent');
}
['@test Ember.copy null prototype object'](assert) {
let obj = Object.create(null);
obj.foo = 'bar';
let copied = null;
expectDeprecation(() => {
copied = copy(obj);
}, 'Use ember-copy addon instead of copy method and Copyable mixin.');
assert.equal(copied.foo, 'bar', 'bar should still be bar');
}
['@test Ember.copy Array'](assert) {
let array = [1, null, new Date(2015, 9, 9), 'four'];
let arrayCopy = null;
expectDeprecation(() => {
arrayCopy = copy(array);
}, 'Use ember-copy addon instead of copy method and Copyable mixin.');
assert.deepEqual(array, arrayCopy, 'array content cloned successfully in new array');
}
['@test Ember.copy cycle detection'](assert) {
let obj = {
foo: {
bar: 'bar',
},
};
obj.foo.foo = obj.foo;
let cycleCopy = null;
expectDeprecation(() => {
cycleCopy = copy(obj, true);
}, 'Use ember-copy addon instead of copy method and Copyable mixin.');
assert.equal(cycleCopy.foo.bar, 'bar');
assert.notEqual(cycleCopy.foo.foo, obj.foo.foo);
assert.strictEqual(cycleCopy.foo.foo, cycleCopy.foo.foo);
}
}
);