Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

Commit

Permalink
allow opts to be undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
nahtnam committed Aug 25, 2019
1 parent 9f54b08 commit 3100f11
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
9 changes: 5 additions & 4 deletions lib/route.js
Expand Up @@ -12,11 +12,12 @@ class Route {
this.disableErrorHandler = false;
this.req = req;
this.res = res;
if (!this.disableRequestLogger && opts.disableRequestLogger) {
this.disableRequestLogger = opts.disableRequestLogger;
const options = opts || {};
if (!this.disableRequestLogger && options.disableRequestLogger) {
this.disableRequestLogger = options.disableRequestLogger;
}
if (!this.disableErrorHandler && opts.disableErrorHandler) {
this.disableErrorHandler = opts.disableErrorHandler;
if (!this.disableErrorHandler && options.disableErrorHandler) {
this.disableErrorHandler = options.disableErrorHandler;
}
}
_getInternalPlugins() {
Expand Down
12 changes: 7 additions & 5 deletions src/route.ts
Expand Up @@ -18,15 +18,17 @@ export default class Route {

public logger: any;

public constructor({ req, res, opts }: { req: IM; res: SR; opts: any }) {
public constructor({ req, res, opts }: { req: IM; res: SR; opts?: any }) {
this.req = req;
this.res = res;

if (!this.disableRequestLogger && opts.disableRequestLogger) {
this.disableRequestLogger = opts.disableRequestLogger;
const options = opts || {};

if (!this.disableRequestLogger && options.disableRequestLogger) {
this.disableRequestLogger = options.disableRequestLogger;
}
if (!this.disableErrorHandler && opts.disableErrorHandler) {
this.disableErrorHandler = opts.disableErrorHandler;
if (!this.disableErrorHandler && options.disableErrorHandler) {
this.disableErrorHandler = options.disableErrorHandler;
}
}

Expand Down
13 changes: 13 additions & 0 deletions tests/route.ts
@@ -0,0 +1,13 @@
import { Route } from '../src/index';

describe('route', () => {
describe('without opts', () => {
it('does not throw', async () => {
expect.assertions(1);
expect(() => new Route({
req: ({} as any),
res: ({} as any),
})).not.toThrow();
});
});
});

0 comments on commit 3100f11

Please sign in to comment.