-
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.
- Loading branch information
Sean Hamilton
committed
Jul 4, 2019
1 parent
2e0c10a
commit 36f03ec
Showing
1 changed file
with
80 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,80 @@ | ||
import { dotNotation, valid, defaults } from '../util'; | ||
|
||
describe('util', () => { | ||
describe('dot notation', () => { | ||
describe('from', () => { | ||
test('should convert a path into dot notation parts', () => { | ||
const path = 'path.to.this.place'; | ||
|
||
const result = dotNotation.from(path); | ||
|
||
expect(result).toHaveLength(4); | ||
}); | ||
|
||
test('should handle escaped dots within paths', () => { | ||
const path = 'path.to.this.dot\\.place'; | ||
|
||
const result = dotNotation.from(path); | ||
|
||
expect(result).toHaveLength(4); | ||
expect(result[3]).toBe('dot.place'); | ||
}); | ||
}); | ||
|
||
describe('to', () => { | ||
test('should convert an array of path parts to a single path string', () => { | ||
const parts = [ | ||
'path', | ||
'to', | ||
'this', | ||
'place', | ||
]; | ||
|
||
const result = dotNotation.to(parts); | ||
|
||
expect(typeof result).toBe('string'); | ||
expect(result).toBe('path.to.this.place'); | ||
}); | ||
|
||
test('should replace dots within part to "\\."', () => { | ||
const parts = [ | ||
'path', | ||
'to', | ||
'this', | ||
'dot.place', | ||
]; | ||
|
||
const result = dotNotation.to(parts); | ||
|
||
expect(result).toBe('path.to.this.dot\\.place'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('valid', () => { | ||
test('should return true of all args are objects', () => { | ||
expect(valid({})).toBe(true); | ||
expect(valid({}, {})).toBe(true); | ||
expect(valid({}, 'testing')).toBe(false); | ||
expect(valid({}, 1)).toBe(false); | ||
expect(valid({}, {}, false)).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('defaults', () => { | ||
test('should merge the two objects', () => { | ||
const objA = { | ||
a: 1, | ||
}; | ||
const objB = { | ||
a: 2, | ||
b: 2, | ||
}; | ||
|
||
const result: OObject = defaults(objA, objB); | ||
|
||
expect(Object.keys(result)).toHaveLength(2); | ||
expect(result.a + result.b).toBe(4); | ||
}); | ||
}); | ||
}); |