forked from eighttrigrams/tsfun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy.spec.ts
55 lines (34 loc) · 1.14 KB
/
copy.spec.ts
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
import { copy } from '../../src/associative'
/**
* tsfun | copy
*
* `copy` creates a shallow copy of an associative collection.
*/
describe('copy', () => {
it('array',() =>
expect(
copy([2,4]))
.toEqual([2, 4]))
it('array instance new, instance value same',() => {
const instance = {a: 'hey'}
const originalColl = [instance, 4]
const copiedColl = copy(originalColl)
expect(copiedColl).not.toBe(originalColl)
expect(copiedColl[0]).toBe(instance)
})
it('object instance new, instance value same', () => {
const instance = {a: 'hey'}
const originalColl = {a: instance, b: 4}
const copiedColl = copy(originalColl)
expect(copiedColl).not.toBe(originalColl)
expect(copiedColl['a']).toBe(instance)
})
it('copy - object, keys mixed numbers and strings', () =>
expect(
copy({a: 1, 2: 2}))
.toEqual({a: 1, 2: 2}))
it('copy - retain existent keys with undefined properties', () =>
expect(
copy({a: 1, 2: undefined}))
.toEqual({a: 1, 2: undefined}))
})