Jasmine Angular 9 test failing because 'unreachable' stack trace at injectableDefOrInjectorDefFactory

前端 未结 2 1000
日久生厌
日久生厌 2021-01-17 23:52

I created an Angular application under 4. I have migrated from version to version and am currently latest version 9. I was reviewing my tests. I have a Login component th

相关标签:
2条回答
  • 2021-01-18 00:04

    You can also create a mocked class to be used as your UserService:

    class MockUserService {
    
      myMethod(): void {
        // mocked logic
      } 
    }
    
    describe('LoginComponent', () => {
    ...
    
    providers: [
        ...
        { provide: UserService, useClass: MockUserService }
    ]
    ...
    
    });
    
    0 讨论(0)
  • 2021-01-18 00:14
    providers: [
        ...
        { provide: UserService, useClass: userServiceSpy }
    ]
    

    Should be changed to:

    providers: [
        ...
        { provide: UserService, useValue: userServiceSpy }
    ]
    
    0 讨论(0)
提交回复
热议问题