Skip to content

Commit 3fee10e

Browse files
committed
feat(testing): TestAppLogger now stores messages for easier assertions and debugging
1 parent 2a1cac5 commit 3fee10e

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

packages/nest-utils/src/http/interceptors/http-logging.interceptor.test.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ describe('HttpLoggingInterceptor', () => {
2424
enableEndToEnd: true,
2525
});
2626
supertest = container.supertest;
27-
// Clear any logger calls from e.g. application startup
28-
vitest.clearAllMocks();
27+
logger.clear();
2928
});
3029

3130
it('should log both request and response', async () => {

packages/nest-utils/src/testing/logging/test.logger.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,18 @@ import { CustomLogger } from '../../logging/custom.logger';
1515
* });
1616
*/
1717
export class TestAppLogger extends CustomLogger {
18-
printMessages = vitest.fn();
18+
/**
19+
* The messages that have been logged. Clear with `clear()`.
20+
*/
21+
messages: unknown[] = [];
22+
23+
printMessages = vitest.fn((messages: unknown[]) => this.messages.push(messages));
24+
25+
/**
26+
* Clears `messages` and all calls to `printMessages`.
27+
*/
28+
clear = () => {
29+
this.printMessages.mockClear();
30+
this.messages = [];
31+
};
1932
}

0 commit comments

Comments
 (0)