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 1 commit
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
24 changes: 24 additions & 0 deletions src/jsutils/__tests__/Path-test.ts
@@ -0,0 +1,24 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';

import type { Path } from '../Path';
import { addPath, pathToArray } from '../Path';

describe('Path', () => {
it('can add a new key to an existing Path', () => {
const first: Path = { prev: undefined, key: 1, typename: 'First' };
const second = addPath(first, 'two', 'Second');
expect(second.prev).to.equal(first);
expect(second.key).to.equal('two');
expect(second.typename).to.equal('Second');
IvanGoncharov marked this conversation as resolved.
Show resolved Hide resolved
});

it('can convert a Path to an array of its keys', () => {
const root: Path = { prev: undefined, key: 0, typename: 'Root' };
const first: Path = { prev: root, key: 'one', typename: 'First' };
const second: Path = { prev: first, key: 2, typename: 'Second' };
IvanGoncharov marked this conversation as resolved.
Show resolved Hide resolved
expect(pathToArray(second))
.to.be.an('array')
IvanGoncharov marked this conversation as resolved.
Show resolved Hide resolved
.that.deep.equals([0, 'one', 2]);
});
});