Skip to content

Commit be6212c

Browse files
committed
Add tests for Path function
1 parent af878f3 commit be6212c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/jsutils/__tests__/Path-test.ts

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

0 commit comments

Comments
 (0)