|
1 | 1 | import { remove } from '.' |
2 | 2 |
|
| 3 | +const user = { |
| 4 | + id: 'e059d01a-7082-4b63-9c70-997491cdcf7c', |
| 5 | + name: 'John Doe', |
| 6 | + category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2', |
| 7 | + |
| 8 | + age: 29 |
| 9 | +} |
| 10 | + |
| 11 | +const userNodes = { |
| 12 | + ...user, |
| 13 | + node: [ |
| 14 | + { |
| 15 | + ...user, |
| 16 | + node: { |
| 17 | + ...user, |
| 18 | + node: { |
| 19 | + ...user |
| 20 | + } |
| 21 | + } |
| 22 | + }, |
| 23 | + { |
| 24 | + ...user, |
| 25 | + node: { |
| 26 | + ...user |
| 27 | + } |
| 28 | + }, |
| 29 | + { |
| 30 | + ...user, |
| 31 | + node: { |
| 32 | + ...user, |
| 33 | + node: { |
| 34 | + ...user |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + ] |
| 39 | +} |
| 40 | + |
3 | 41 | describe('remove', () => { |
4 | | - it('should remove a specific key', () => { |
5 | | - expect(remove({ id: 1, foo: 2, bar: 3 }, 'foo')).toStrictEqual({ |
6 | | - bar: 3, |
7 | | - id: 1 |
| 42 | + it('should remove the id from user', () => { |
| 43 | + expect(remove(user, 'id')).toStrictEqual({ |
| 44 | + name: 'John Doe', |
| 45 | + category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2', |
| 46 | + |
| 47 | + age: 29 |
8 | 48 | }) |
9 | 49 | }) |
10 | 50 |
|
11 | | - it('should remove a specific key from different levels', () => { |
12 | | - expect( |
13 | | - remove( |
| 51 | + it('should remove the category from user', () => { |
| 52 | + expect(remove(user, 'category')).toStrictEqual({ |
| 53 | + id: 'e059d01a-7082-4b63-9c70-997491cdcf7c', |
| 54 | + name: 'John Doe', |
| 55 | + |
| 56 | + age: 29 |
| 57 | + }) |
| 58 | + }) |
| 59 | + |
| 60 | + it('should remove category and email from user', () => { |
| 61 | + expect(remove(user, ['category', 'email'])).toStrictEqual({ |
| 62 | + id: 'e059d01a-7082-4b63-9c70-997491cdcf7c', |
| 63 | + name: 'John Doe', |
| 64 | + age: 29 |
| 65 | + }) |
| 66 | + }) |
| 67 | + |
| 68 | + it('should remove age from user', () => { |
| 69 | + expect(remove(user, 'age')).toStrictEqual({ |
| 70 | + id: 'e059d01a-7082-4b63-9c70-997491cdcf7c', |
| 71 | + name: 'John Doe', |
| 72 | + category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2', |
| 73 | + |
| 74 | + }) |
| 75 | + }) |
| 76 | + |
| 77 | + it('should remove id and age from user', () => { |
| 78 | + expect(remove(user, ['id', 'age'])).toStrictEqual({ |
| 79 | + name: 'John Doe', |
| 80 | + category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2', |
| 81 | + |
| 82 | + }) |
| 83 | + }) |
| 84 | + |
| 85 | + it('should remove id from userNodes', () => { |
| 86 | + expect(remove(userNodes, 'id')).toStrictEqual({ |
| 87 | + name: 'John Doe', |
| 88 | + category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2', |
| 89 | + |
| 90 | + age: 29, |
| 91 | + node: [ |
14 | 92 | { |
15 | | - id: 1, |
16 | | - foo: 1, |
17 | | - children: { |
18 | | - id: 2, |
19 | | - foo: 2, |
20 | | - children: {} |
| 93 | + name: 'John Doe', |
| 94 | + category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2', |
| 95 | + |
| 96 | + age: 29, |
| 97 | + node: { |
| 98 | + name: 'John Doe', |
| 99 | + category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2', |
| 100 | + |
| 101 | + age: 29, |
| 102 | + node: { |
| 103 | + name: 'John Doe', |
| 104 | + category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2', |
| 105 | + |
| 106 | + age: 29 |
| 107 | + } |
21 | 108 | } |
22 | 109 | }, |
23 | | - 'foo' |
24 | | - ) |
25 | | - ).toStrictEqual({ |
26 | | - children: { |
27 | | - children: {}, |
28 | | - id: 2 |
29 | | - }, |
30 | | - id: 1 |
| 110 | + { |
| 111 | + name: 'John Doe', |
| 112 | + category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2', |
| 113 | + |
| 114 | + age: 29, |
| 115 | + node: { |
| 116 | + name: 'John Doe', |
| 117 | + category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2', |
| 118 | + |
| 119 | + age: 29 |
| 120 | + } |
| 121 | + }, |
| 122 | + { |
| 123 | + name: 'John Doe', |
| 124 | + category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2', |
| 125 | + |
| 126 | + age: 29, |
| 127 | + node: { |
| 128 | + name: 'John Doe', |
| 129 | + category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2', |
| 130 | + |
| 131 | + age: 29, |
| 132 | + node: { |
| 133 | + name: 'John Doe', |
| 134 | + category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2', |
| 135 | + |
| 136 | + age: 29 |
| 137 | + } |
| 138 | + } |
| 139 | + } |
| 140 | + ] |
31 | 141 | }) |
32 | 142 | }) |
33 | 143 |
|
34 | | - it('should remove multiple keys', () => { |
35 | | - expect(remove({ id: 1, foo: 2, bar: 3, baz: [] }, ['foo', 'bar'])).toStrictEqual({ baz: [], id: 1 }) |
36 | | - }) |
37 | | -}) |
38 | | - |
39 | | -it('should remove multiple keys from different levels', () => { |
40 | | - expect( |
41 | | - remove( |
42 | | - { |
43 | | - id: 1, |
44 | | - foo: 1, |
45 | | - bar: 1, |
46 | | - children: { |
47 | | - id: 2, |
48 | | - foo: 2, |
49 | | - bar: 2, |
50 | | - children: {} |
| 144 | + it('should remove id and node from userNodes', () => { |
| 145 | + expect(remove(userNodes, ['email', 'category', 'age'])).toStrictEqual({ |
| 146 | + id: 'e059d01a-7082-4b63-9c70-997491cdcf7c', |
| 147 | + name: 'John Doe', |
| 148 | + node: [ |
| 149 | + { |
| 150 | + id: 'e059d01a-7082-4b63-9c70-997491cdcf7c', |
| 151 | + name: 'John Doe', |
| 152 | + node: { |
| 153 | + id: 'e059d01a-7082-4b63-9c70-997491cdcf7c', |
| 154 | + name: 'John Doe', |
| 155 | + node: { |
| 156 | + id: 'e059d01a-7082-4b63-9c70-997491cdcf7c', |
| 157 | + name: 'John Doe' |
| 158 | + } |
| 159 | + } |
| 160 | + }, |
| 161 | + { |
| 162 | + id: 'e059d01a-7082-4b63-9c70-997491cdcf7c', |
| 163 | + name: 'John Doe', |
| 164 | + node: { |
| 165 | + id: 'e059d01a-7082-4b63-9c70-997491cdcf7c', |
| 166 | + name: 'John Doe' |
| 167 | + } |
| 168 | + }, |
| 169 | + { |
| 170 | + id: 'e059d01a-7082-4b63-9c70-997491cdcf7c', |
| 171 | + name: 'John Doe', |
| 172 | + node: { |
| 173 | + id: 'e059d01a-7082-4b63-9c70-997491cdcf7c', |
| 174 | + name: 'John Doe', |
| 175 | + node: { |
| 176 | + id: 'e059d01a-7082-4b63-9c70-997491cdcf7c', |
| 177 | + name: 'John Doe' |
| 178 | + } |
| 179 | + } |
51 | 180 | } |
52 | | - }, |
53 | | - ['foo', 'bar'] |
54 | | - ) |
55 | | - ).toStrictEqual({ |
56 | | - children: { |
57 | | - children: {}, |
58 | | - id: 2 |
59 | | - }, |
60 | | - id: 1 |
| 181 | + ] |
| 182 | + }) |
61 | 183 | }) |
62 | 184 | }) |
0 commit comments