In my service I have created a Subject 'allDataChange'
allDataChange = new Subject<AllData>();
In my component I have
ngOnInit() {
...
this.detailsService.allDataChange.subscribe((data) => {
... something gets done here
});
}
In my test... well I've got no clue what I'm doing, but whenever I run the test I see an errorTypeError: this.detailsService.allDataChange.subscribe is not function.
I've tried a dozen things. Well, it feels like a dozen. It may be that I've just tried the same thing 12 times. At this point, I don't know.
Here's the test setup and test:
describe('DetailsTabComponent', () => {
let component: DetailsTabComponent;
let fixture: ComponentFixture<DetailsTabComponent>;
let appConfigServiceSpy: jasmine.SpyObj<AppConfigService>;
let detailsServiceSpy: jasmine.SpyObj<RequisitionDetailsService>;
beforeEach(async(() => {
const spy = jasmine.createSpyObj('AppConfigService', ['loadAppConfig']);
const detailsSpy = jasmine.createSpyObj('RequisitionDetailsService', ['getAllData', 'allDataChange']);
TestBed.configureTestingModule({
declarations: [
DetailsTabComponent
],
imports: [
OwlDateTimeModule,
OwlNativeDateTimeModule,
HttpClientTestingModule
],
providers: [
{provide: AppConfigService, useValue: spy},
{provide: RequisitionDetailsService, useValue: detailsSpy}
]
})
.compileComponents();
appConfigServiceSpy = TestBed.get(AppConfigService);
detailsServiceSpy = TestBed.get(RequisitionDetailsService);
}));
beforeEach(() => {
fixture = TestBed.createComponent(DetailsTabComponent);
detailsServiceSpy.getAllData.and.returnValue(goodData);
// detailsServiceSpy.allDataChange.and.returnValue(goodData);
component = fixture.componentInstance;
fixture.detectChanges();
fixture.debugElement.injector.get(RequisitionDetailsService);
});
it('should create', async(() => {
const stubValue = 'http://test.test/';
appConfigServiceSpy.loadAppConfig.and.returnValue(stubValue);
expect(component).toBeTruthy();
}));
});
I'm using Angular 6 and jasmine-core version 2.99.1. I've been trying to get this test to pass for two days, and the almighty Google has been absolutely no help. Can anyone tell me how to get past this 'blah.blah.subscribe is not a function error' and make this test pass?