155
rated 0 times
[
162]
[
7]
/ answers: 1 / hits: 5468
/ 3 Years ago, wed, january 13, 2021, 12:00:00
I am trying to get a service method to pass inside a unit test, however it keeps failing:
"TypeError: this.eventsService.getEvent is not a function"
My code inside my component:
constructor(
private eventsService: EventsService
)
this.subscriptions.add(
this.eventsService.getEvent().subscribe(events => {
this.events = events;
this.soSomeMethod();
})
);
// Also have a V2 method, unsure if it matters but adding it for clarity
this.subscriptions.add(
this.eventsService.getEventV2().subscribe(eventsV2 => {
this.eventsV2 = eventsV2;
this.soSomeMethod();
})
);
This is the service in question:
public getEvent(): Observable<event[]> {
return combineLatest(this.store.select(getEventStore), this.store.select(getEvents)).pipe(
map(state => {
// do something
})
);
}
public getEventV2(): Observable<event[]> {
return combineLatest(this.store.select(getEventStore), this.store.select(getEvents)).pipe(
map(state => {
// do something
})
);
}
My testing has the methods inside the providers:
{ provide: EventsService, useValue: { getEvent: () => of([])}},
{ provide: EventsService, useValue: { getEventV2: () => of([])}},
More From » angular