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)? 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.
正如评论中提到的,我在这里找到了可能会遇到此问题的任何人的解决方案。
As explained in NGXLogger docs , use LoggerTestingModule
.
First import LoggerTestingModule
in your AppModule
.
Then provide NGXLogger
in tests using NGXLoggerMock
:
TestBed.configureTestingModule({
imports: [
{ provide: NGXLogger, useValue: NGXLoggerMock },
],
...
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.