-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(defaults): add defaults and shallowDefaults
Add tests for new defaults and shallowDefaults methods
- Loading branch information
Sean Hamilton
committed
Nov 20, 2019
1 parent
6e27a72
commit 93f77b4
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import defaults from '../defaults' | ||
import { OObject } from '../types' | ||
|
||
describe('defaults', (): void => { | ||
test('should merge all objects', (): void => { | ||
const getDefaults = defaults({ a: 1 }) | ||
const b = { b: 2 } | ||
const c = { c: 3 } | ||
const keys = Object.keys(getDefaults(b, c)) | ||
|
||
expect(keys).toHaveLength(3) | ||
}) | ||
|
||
test('should deep merge objects', (): void => { | ||
const getDefaults = defaults({ a: 1, b: { c: 2 } }) | ||
const b = { b: { c: 3 } } | ||
|
||
expect(getDefaults(b).b.c).toBe(3) | ||
}) | ||
|
||
test('should throw TypeError if follow argument is invalid', (): void => { | ||
const invalidObj: unknown = 'testing' | ||
|
||
expect((): OObject => defaults(invalidObj as OObject)) | ||
.toThrow(new TypeError('Expected Object, got string testing')) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import shallowDefaults from '../shallowDefaults' | ||
import { OObject } from '../types' | ||
|
||
describe('defaults', (): void => { | ||
test('should merge all objects', (): void => { | ||
const getDefaults = shallowDefaults({ a: 1 }) | ||
const b = { b: 2 } | ||
const c = { c: 3 } | ||
const keys = Object.keys(getDefaults(b, c)) | ||
|
||
expect(keys).toHaveLength(3) | ||
}) | ||
|
||
test('should shallow merge objects', (): void => { | ||
const getDefaults = shallowDefaults({ a: 1, b: { c: 2, d: 3 } }) | ||
const b = { a: 2, b: { c: 3 } } | ||
const result = getDefaults(b) | ||
|
||
expect(result.a).toBe(2) | ||
expect(result.b.c).toBe(3) | ||
expect(result.b.d).toBeUndefined() | ||
}) | ||
|
||
test('should throw TypeError if follow argument is invalid', (): void => { | ||
const invalidObj: unknown = 'testing' | ||
|
||
expect((): OObject => shallowDefaults(invalidObj as OObject)) | ||
.toThrow(new TypeError('Expected Object, got string testing')) | ||
}) | ||
}) |