|
| 1 | +import { describe, expect, it } from 'vitest' |
| 2 | +import { withDefaultObject } from '.' |
| 3 | + |
| 4 | +describe('default object', () => { |
| 5 | + it('default return', () => { |
| 6 | + expect( |
| 7 | + withDefaultObject({ x: 1 }, { x: 0, y: 0 }), |
| 8 | + ).toMatchInlineSnapshot(` |
| 9 | + { |
| 10 | + "x": 1, |
| 11 | + "y": 0, |
| 12 | + } |
| 13 | + `) |
| 14 | + }) |
| 15 | + |
| 16 | + it('with not return', () => { |
| 17 | + const target = { x: 1 } |
| 18 | + const source = { x: 0, y: 0 } |
| 19 | + withDefaultObject(target, source) |
| 20 | + expect(target).toMatchInlineSnapshot(` |
| 21 | + { |
| 22 | + "x": 1, |
| 23 | + "y": 0, |
| 24 | + } |
| 25 | + `) |
| 26 | + }) |
| 27 | + |
| 28 | + it('with {}', () => { |
| 29 | + const target = {} |
| 30 | + const source = { x: 0, y: 0 } |
| 31 | + withDefaultObject(target, source) |
| 32 | + expect(target).toMatchInlineSnapshot(` |
| 33 | + { |
| 34 | + "x": 0, |
| 35 | + "y": 0, |
| 36 | + } |
| 37 | + `) |
| 38 | + }) |
| 39 | + |
| 40 | + it('with undefined', () => { |
| 41 | + let target |
| 42 | + const source = { x: 0, y: 0 } |
| 43 | + withDefaultObject((target || (target = {})), source) |
| 44 | + |
| 45 | + expect(target).toMatchInlineSnapshot(` |
| 46 | + { |
| 47 | + "x": 0, |
| 48 | + "y": 0, |
| 49 | + } |
| 50 | + `) |
| 51 | + |
| 52 | + expect(withDefaultObject(target, source)).toMatchInlineSnapshot(` |
| 53 | + { |
| 54 | + "x": 0, |
| 55 | + "y": 0, |
| 56 | + } |
| 57 | + `) |
| 58 | + }) |
| 59 | + |
| 60 | + it('with default undefined', () => { |
| 61 | + const target = undefined |
| 62 | + const source = { x: 0, y: 0 } |
| 63 | + withDefaultObject(target, source) |
| 64 | + |
| 65 | + // TODO: |
| 66 | + expect(target).toMatchInlineSnapshot('undefined') |
| 67 | + }) |
| 68 | +}) |
0 commit comments