Skip to content

Commit f42cee9

Browse files
CitoIvanGoncharov
andauthored
jsutils: add test for Path functions (#2478)
Co-authored-by: Ivan Goncharov <[email protected]>
1 parent 4c9bf03 commit f42cee9

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/jsutils/__tests__/Path-test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { expect } from 'chai';
2+
import { describe, it } from 'mocha';
3+
4+
import { addPath, pathToArray } from '../Path';
5+
6+
describe('Path', () => {
7+
it('can create a Path', () => {
8+
const first = addPath(undefined, 1, 'First');
9+
10+
expect(first).to.deep.equal({
11+
prev: undefined,
12+
key: 1,
13+
typename: 'First',
14+
});
15+
});
16+
17+
it('can add a new key to an existing Path', () => {
18+
const first = addPath(undefined, 1, 'First');
19+
const second = addPath(first, 'two', 'Second');
20+
21+
expect(second).to.deep.equal({
22+
prev: first,
23+
key: 'two',
24+
typename: 'Second',
25+
});
26+
});
27+
28+
it('can convert a Path to an array of its keys', () => {
29+
const root = addPath(undefined, 0, 'Root');
30+
const first = addPath(root, 'one', 'First');
31+
const second = addPath(first, 2, 'Second');
32+
33+
const path = pathToArray(second);
34+
expect(path).to.deep.equal([0, 'one', 2]);
35+
});
36+
});

0 commit comments

Comments
 (0)