-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathlogger-error-interceptor.spec.ts
50 lines (44 loc) · 1.37 KB
/
logger-error-interceptor.spec.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { Controller, Get } from '@nestjs/common';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { LoggerErrorInterceptor } from '../src';
import { platforms } from './utils/platforms';
import { TestCase } from './utils/test-case';
describe('error intercepting', () => {
for (const PlatformAdapter of platforms) {
describe(PlatformAdapter.name, () => {
it('logger is publicly accessible', async () => {
class CustomError extends Error {
constructor(message?: string) {
super(message);
Object.setPrototypeOf(this, new.target.prototype);
Error.captureStackTrace(this, this.constructor);
}
}
@Controller('/')
class TestController {
@Get()
get() {
throw new CustomError('Test Error Message');
}
}
const result = await new TestCase(new PlatformAdapter(), {
controllers: [TestController],
providers: [
{ provide: APP_INTERCEPTOR, useClass: LoggerErrorInterceptor },
],
})
.forRoot()
.expectError(500)
.run();
expect(
result.find((log) => log.msg === 'request errored'),
).toMatchObject({
err: {
message: 'Test Error Message',
type: 'CustomError',
},
});
});
});
}
});