简体   繁体   English

具有 ngx-logger 依赖项的 angular 6 单元测试

[英]Unit testing in angular 6 with ngx-logger dependency

Is there a way to properly test classes that have ngx-logger as dependency in angular (Assuming we may be using some known framework for testing, like jasmine)?有没有办法正确测试具有ngx-logger作为 angular 依赖项的类(假设我们可能正在使用一些已知的框架进行测试,例如 jasmine)? So far there isn't a resource that can help me to provide a use case where the ngx-logger was mocked or provided in unit tests for classes that have this dependency.到目前为止,没有任何资源可以帮助我提供一个用例,其中ngx-loggerngx-logger或在单元测试中为具有这种依赖性的类提供。

正如评论中提到的,我在这里找到了可能会遇到此问题的任何人的解决方案。

As explained in NGXLogger docs , use LoggerTestingModule .NGXLogger 文档中所述,使用LoggerTestingModule

First import LoggerTestingModule in your AppModule .首先进口LoggerTestingModule在你AppModule

Then provide NGXLogger in tests using NGXLoggerMock :然后提供NGXLogger使用测试NGXLoggerMock

TestBed.configureTestingModule({
  imports: [
    { provide: NGXLogger, useValue: NGXLoggerMock },
  ],
  ...
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM