read property 'subscribe' of undefined
                  
                  
                      beforeEach(async(() => {
                  
                  
                          const pagesServiceStub = {
                  
                  
                              get: () => ({
                  
                  
                                  subscribe: () => ({})
                  
                  
                              })
                  
                  
                          };
                  
                  
                          TestBed.configureTestingModule({
                  
                  
                              declarations: [PageListComponent],
                  
                  
                              schemas: [NO_ERRORS_SCHEMA],
                  
                  
                              providers: [
                  
                  
                                  { provide: PagesService, useValue: pagesServiceStub },
                  
                  
                              ]
                  
                  
                          }).compileComponents();
                  
                  
                      }));
                  
                  
                  
                  
                  
                      beforeEach(() => {
                  
                  
                          fixture = TestBed.createComponent(PageListComponent);
                  
                  
                          comp = fixture.componentInstance;
                  
                  
                          fixture.detectChanges();
                  
                  
                      });
                  
                  
                  ...
                  
                  
                          it('makes expected calls', () => {
                  
                  
                              const pagesServiceStubb: PagesService = fixture.debugElement.injector.get(PagesService);
                  
                  
                              spyOn(pagesServiceStubb, 'get');
                  
                  
                              comp.ngOnInit();
                  
                  
                              expect(pagesServiceStubb.get).toHaveBeenCalled();
                  
                  
                          });
                  
                  
                  
                  
                  
                  В чём может быть загвоздка ?
                  
                  
                
spyOn(pagesServiceStubb, 'get'); перекрывает стаб, добавьте .and.callThrough() или and.returnValue(Observable.of(null));
Обсуждают сегодня