Skip to content

Commit bed7838

Browse files
committed
Add helpful error messaging
- e.g., in case a path gets typoed
1 parent 9ed97d4 commit bed7838

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

x-pack/plugins/enterprise_search/server/__mocks__/router.mock.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@ export class MockRouter {
5151

5252
public callRoute = async (request: TMockRouterRequest) => {
5353
const routerCalls = this.router[this.method].mock.calls as any[];
54+
if (!routerCalls.length) throw new Error('No routes registered.');
55+
5456
const route = routerCalls.find(([router]: any) => router.path === this.path);
55-
const [, handler] = route;
57+
if (!route) throw new Error('No matching registered routes found - check method/path keys');
5658

59+
const [, handler] = route;
5760
const context = {} as jest.Mocked<RequestHandlerContext>;
5861
await handler(context, httpServerMock.createKibanaRequest(request as any), this.response);
5962
};

0 commit comments

Comments
 (0)