Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsutils: add test for Path functions #2478

Merged
merged 2 commits into from Oct 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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]);
});
});