I'm trying to test a unit test for a component into angular, into the component I have a filterTypeahead function that expect a string, this value is inserted into a Subject, when it happen I have other code for dispatch a loadData, so with filteredData$ observable I subscribe to it for get the data
it('should not get the data if there are no input value', fakeAsync(async () => {
component.ngAfterViewInit();
component.filterTypeahead({ value: '' });
tick(500);
component.filteredData$.subscribe((value: any[]) => {
expect(value).toEqual([]);
});
}));
But I don't know why I'm getting the flollow error
TypeError: Cannot read properties of undefined (reading 'data') on selectors
let component: WidgetComponent;
let fixture: ComponentFixture<WidgetComponent>;
let store: MockStore;
const initialState = {
data: []
};
beforeEach((() => {
TestBed.configureTestingModule({
declarations: [WidgetComponent],
schemas: [NO_ERRORS_SCHEMA],
providers: [
provideMockStore({ initialState })
],
}).compileComponents();
store = TestBed.inject(MockStore);
spyOn(store, 'dispatch');
}));