forked from ahmadnassri/node-stringify-clone
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
54 lines (43 loc) · 896 Bytes
/
index.js
File metadata and controls
54 lines (43 loc) · 896 Bytes
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
'use strict'
const clone = require('..')
const tap = require('tap')
tap.test('simple', assert => {
assert.plan(2)
const original = {
number: 10,
string: 'foo',
boolean: true
}
const cloned = clone(original)
assert.notEqual(cloned, original)
assert.same(cloned, original)
})
tap.test('complex', assert => {
assert.plan(2)
const date = new Date()
const original = {
objects: {
array: [ null, undefined, date, /deepcopy/ig ],
to: null,
object: {
number: NaN,
string: 'A',
boolean: true
}
}
}
const expected = {
objects: {
array: [ null, null, date.toISOString(), {} ],
to: null,
object: {
number: null,
string: 'A',
boolean: true
}
}
}
const cloned = clone(original)
assert.notEqual(cloned, original)
assert.same(cloned, expected)
})