Skip to content

Commit

Permalink
Test for path with an optional field
Browse files Browse the repository at this point in the history
  • Loading branch information
bsalex committed Nov 15, 2020
1 parent 210620f commit 3d46b6e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ type TestType = {
}
};

interface OptionalThing {
foo: string;
bar?: string;
}

const testAdditionalHandlers = {
$abs: (path: string[]) => typedPath<TestType, typeof testAdditionalHandlers>(testAdditionalHandlers, ['', ...path]),
$url: (path: string[]) => path.join('/')
Expand Down Expand Up @@ -53,6 +58,10 @@ describe('Typed path', () => {
expect(tp<TestType>().a.testFunc.$raw).to.deep.equal(['a', 'testFunc']);
});

it('should get path with optional fields', () => {
expect(tp<OptionalThing>().bar.$path).to.equal('bar');
});

it('should get path with symbol', () => {
expect(tp<TestType>().a[sym].g.$path).to.equal('a.Symbol(SomeSymbol).g');
expect(tp<TestType>().a[sym].g.$raw).to.deep.equal(['a', 'Symbol(SomeSymbol)', 'g']);
Expand Down

0 comments on commit 3d46b6e

Please sign in to comment.