-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
application.test.ts
34 lines (27 loc) · 1.15 KB
/
application.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright IBM Corp. 2013,2017. All Rights Reserved.
// Node module: @loopback/core
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
import {expect, ShotRequest} from '@loopback/testlab';
import {Application, ServerRequest} from '../../..';
describe('Application', () => {
describe('"logError" binding', () => {
it('provides a default', async () => {
const app = new Application();
const logError = await app.get('logError');
expect(logError.length).to.equal(3); // (err, statusCode, request)
});
it('can be customized by overriding Application._logError() method', async () => {
let lastLog: string = 'logError() was not called';
class MyApp extends Application {
protected _logError(err: Error, statusCode: number, request: ServerRequest) {
lastLog = `${request.url} ${statusCode} ${err.message}`;
}
}
const app = new MyApp();
const logError = await app.get('logError');
logError(new Error('test-error'), 400, new ShotRequest({url: '/'}));
expect(lastLog).to.equal('/ 400 test-error');
});
});
});