admin管理员组文章数量:1129102
I am using nestjs-pino
in my NestJS project, and I'd like to test that the customProps
I am assigning actually work to either use the value of a req
header I send in or use a generated uuid.
import { v4 as uuidv4 } from 'uuid';
import { LoggerModule } from 'nestjs-pino';
@Module({
imports: [
LoggerModule.forRoot({
pinoHttp: {
customProps: (req) => ({
requestId: req.headers['some-header'] ?? uuidv4(),
}),
},
}),
// Other module imports
],
controllers: [ /* controller here */ ],
})
export class AppModule {}
I have a test file set up that tests the LoggerModule is of the correct type, but I'm not sure how to delve deeper into it, to test the actual usage?
import { Test, TestingModule } from '@nestjs/testing';
import { LoggerModule } from 'nestjs-pino';
import { AppModule } from './app.module';
describe('AppModule', () => {
let appModule: TestingModule;
beforeEach(async () => {
appModule = await Test.createTestingModule({
imports: [AppModule],
})pile();
});
// This test passes
it('should load LoggerModule', () => {
const loggerModule = appModule.get(LoggerModule);
expect(loggerModule).toBeInstanceOf(LoggerModule);
});
// Attempt to at least check that "forRoot" had been called - FAILS
fit('should load LoggerModule with custom props', () => {
const loggerModule = appModule.get(LoggerModule);
expect(LoggerModule.forRoot).toHaveBeenCalled();
});
});
本文标签: unit testingHow to test my pino customprops implementationStack Overflow
版权声明:本文标题:unit testing - How to test my pino customprops implementation? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736733687a1950135.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论