Yes, you need to make fun of ngrx/store , but not just Store. The store expects three arguments; one of the types of Observable and two types of Observer, which is the interface. So, I tried two things. Passing null values ββto the StoreMock super() constructor, but this failed in my statement. My other solution was to implement an Observer interface with a layout class (in this case observable). That way, I could pass certain values ββto the super StoreMock constructor.
This is just an illustrative example. ObservableMock does not actually make fun of any functionality that I am trying to test in my application. It serves as a means of protection, so the Store can be entered as a provider in the component that I am trying to verify.
Since Observer is an interface, you must implement its function declarations in mock: next , error and complete .
class ObservableMock implements Observer<any> { closed?: boolean = false;
You can now add the Store as a provider in the Component test module.
describe('Component:Typeahead', () => { beforeEach(() => { TestBed.configureTestingModule({ imports: [...], declarations: [Typeahead], providers: [ {provide: Store, useClass: StoreMock} // NOTICE useClass instead of useValue ] }).compileComponents(); }); });
I am sure there are other ways to do this. Therefore, if anyone has other answers, please write them!
source share