Skip to content

Commit

Permalink
fix: support WCs with result property (#889)
Browse files Browse the repository at this point in the history
  • Loading branch information
platosha authored Oct 8, 2024
1 parent 070e918 commit ffa94b1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/resolver/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ function isDescendantRoute<T, R extends AnyObject, C extends AnyObject>(
}

function isRouteContext<T, R extends AnyObject, C extends AnyObject>(value: unknown): value is RouteContext<T, R, C> {
return !!value && typeof value === 'object' && 'result' in value;
return (
!!value &&
typeof value === 'object' &&
'next' in value &&
'params' in value &&
'result' in value &&
'route' in value
);
}

export interface ResolutionErrorOptions extends ErrorOptions {
Expand Down
14 changes: 14 additions & 0 deletions test/resolver/resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,20 @@ describe('Resolver', () => {
expect(action.calledOnce).to.be.true;
expect(middleware.calledOnce).to.be.true;
});

it('should match routes with object result', async () => {
const resolver = new Resolver([
{
action() {
return { result: 'ok' };
},
path: '/match',
},
]);

const context = await resolver.resolve('/match');
expect(context).to.have.property('result').that.deep.equals({ result: 'ok' });
});
});

// describe('Resolver.__createUrl(path, base) hook', () => {
Expand Down

0 comments on commit ffa94b1

Please # to comment.