Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jsutils: add test for Path functions (#2478)
Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com>
- Loading branch information
1 parent
4c9bf03
commit f42cee9
Showing
1 changed file
with
36 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,36 @@ | ||
import { expect } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
|
||
import { addPath, pathToArray } from '../Path'; | ||
|
||
describe('Path', () => { | ||
it('can create a Path', () => { | ||
const first = addPath(undefined, 1, 'First'); | ||
|
||
expect(first).to.deep.equal({ | ||
prev: undefined, | ||
key: 1, | ||
typename: 'First', | ||
}); | ||
}); | ||
|
||
it('can add a new key to an existing Path', () => { | ||
const first = addPath(undefined, 1, 'First'); | ||
const second = addPath(first, 'two', 'Second'); | ||
|
||
expect(second).to.deep.equal({ | ||
prev: first, | ||
key: 'two', | ||
typename: 'Second', | ||
}); | ||
}); | ||
|
||
it('can convert a Path to an array of its keys', () => { | ||
const root = addPath(undefined, 0, 'Root'); | ||
const first = addPath(root, 'one', 'First'); | ||
const second = addPath(first, 2, 'Second'); | ||
|
||
const path = pathToArray(second); | ||
expect(path).to.deep.equal([0, 'one', 2]); | ||
}); | ||
}); |