I have a few angular components that I want to test and make sure that they are working.
The idea of the component in it's simplest form is to list datapoints. Each of these datapoints should be removable via and API.
So the flow as it is setup would be
- ngrx store is populated with datapoints from the api
- an angular component renders all points as a list
- A user clicks the delete button which dispatches a
deleteaction - an effect listens to this action and calls an api to delete it, and dispatches a
deletedaction to the store once done - A reducer listens to the
deletedaction and removes the point from the store - The component re-renders and the point is removed
I have all of this working on it's own, but as said I want to create a test for it using testing-library. The issue is that no matter what I try, I can't seem to get the point to disappear.
here is how I render the component:
render(DatapointPageComponent, {
providers: [
provideMockStore({
initialState: { ...APPLICATION_STATE },
}),
{
provide: DatapointService,
useValue: {
deleteIntegration() {
console.log('mock delete');
return of(true);
},
},
},
],
declarations: [DatapointListComponent],
imports: [
AppModule,
StoreModule.forRoot({}),
EffectsModule.forRoot(DatapointEffects),
],
schemas: [NO_ERRORS_SCHEMA],
});
Can add as well, that I do not get the mock delete console log that I am expecting.
Is there something obvious that I am doing wrong?
I'm having to assume
provideMockStoreis coming from@ngrx/store/testingbecause you didn't specify it and left out your imports in your code.Given that likelihood, if you read the documentation that's the normal behavior
https://ngrx.io/guide/store/testing