小编Wir*_*nan的帖子

在玩笑中模拟 window.crypto.getRandomValues

我想开玩笑地嘲笑window.crypto.getRandomValues一下。我已经尝试过了jest.spyOn,但没有成功。

javascript cryptography mocking jestjs

2
推荐指数
1
解决办法
9459
查看次数

JEST 的 Nestjs 日志服务

在 Jest 中执行时,我在查看 Nestjs 内的日志时遇到问题。我可以设置在运行 Nestjs 时查看记录器,但通过 Jest 运行时。记录器未打印在屏幕上。

以下是用于设置测试模块的代码。

const module: TestingModule = await Test.createTestingModule({
  imports: [HttpModule, ScheduleModule.forRoot()],
  controllers: [ExampleController],
  providers: [ExampleService, Logger],
}).compile();

module.useLogger(['error', 'warn', 'log', 'debug', 'verbose']);
Run Code Online (Sandbox Code Playgroud)

在ExampleController中

import { Controller, Get, Logger } from '@nestjs/common';

@Controller('example')
export class ExampleController {
  private readonly logger = new Logger(ExampleController.name);

  @Get()
  getExample(): string {
    this.logger.debug('example');
    return 'example';
  }
}
Run Code Online (Sandbox Code Playgroud)

在 Jest 上运行时不会显示此调试消息。

logging jestjs nestjs

0
推荐指数
1
解决办法
892
查看次数

标签 统计

jestjs ×2

cryptography ×1

javascript ×1

logging ×1

mocking ×1

nestjs ×1