Skip to content

Commit

Permalink
jsutils: add test for Path functions (#2478)
Browse files Browse the repository at this point in the history
Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com>
  • Loading branch information
Cito and IvanGoncharov committed Oct 19, 2021
1 parent 4c9bf03 commit f42cee9
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/jsutils/__tests__/Path-test.ts
@@ -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]);
});
});

0 comments on commit f42cee9

Please sign in to comment.