|
2 | 2 |
|
3 | 3 | const deepAssign = require('../deep_assign')
|
4 | 4 |
|
5 |
| -test('deep assign property', () => { |
6 |
| - const object = { foo: { bar: { } } } |
7 |
| - const path = 'foo.bar' |
8 |
| - const value = { x: 1, y: 2 } |
9 |
| - const expectation = { foo: { bar: { x: 1, y: 2 } } } |
10 |
| - expect(deepAssign(object, path, value)).toEqual(expectation) |
| 5 | +describe('deepAssign()', () => { |
| 6 | + test('deeply assigns nested properties', () => { |
| 7 | + const object = { foo: { bar: { } } } |
| 8 | + const path = 'foo.bar' |
| 9 | + const value = { x: 1, y: 2 } |
| 10 | + const expectation = { foo: { bar: { x: 1, y: 2 } } } |
| 11 | + expect(deepAssign(object, path, value)).toEqual(expectation) |
| 12 | + }) |
| 13 | + |
| 14 | + test('allows assignment of a literal false', () => { |
| 15 | + const object = { foo: { bar: { } } } |
| 16 | + const path = 'foo.bar' |
| 17 | + const value = false |
| 18 | + const expectation = { foo: { bar: false } } |
| 19 | + expect(deepAssign(object, path, value)).toEqual(expectation) |
| 20 | + }) |
| 21 | + |
| 22 | + test('does not allow assignment of other falsy values', () => { |
| 23 | + const object = { foo: { bar: { } } } |
| 24 | + const path = 'foo.bar' |
| 25 | + const values = [undefined, null, 0, ''] |
| 26 | + |
| 27 | + values.forEach(value => { |
| 28 | + const expectation = new Error(`Value can't be ${value}`) |
| 29 | + expect(() => deepAssign(object, path, value)).toThrow(expectation) |
| 30 | + }) |
| 31 | + }) |
11 | 32 | })
|
0 commit comments