Skip to content

Commit 20d443e

Browse files
committed
jsutils: add test for Path functions
1 parent 63c2009 commit 20d443e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/jsutils/__tests__/Path-test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// @flow strict
2+
3+
import { expect } from 'chai';
4+
import { describe, it } from 'mocha';
5+
6+
import { addPath, pathToArray } from '../Path';
7+
import { type Path } from '../Path';
8+
9+
describe('Path', () => {
10+
it('can add a new key to an existing Path', () => {
11+
const first: Path = { prev: undefined, key: 1 };
12+
const second = addPath(first, 'two');
13+
expect(second.prev).to.equal(first);
14+
expect(second.key).to.equal('two');
15+
});
16+
17+
it('can convert a Path to an array of its keys', () => {
18+
const root: Path = { prev: undefined, key: 0 };
19+
const first = { prev: root, key: 'one' };
20+
const second = { prev: first, key: 2 };
21+
expect(pathToArray(second))
22+
.to.be.an('array')
23+
.that.deep.equals([0, 'one', 2]);
24+
});
25+
});

0 commit comments

Comments
 (0)