Hi,
I am trying to write a unit test (in Ang4) trying to test connection to search for some data, a single test in spec.ts
It gives me error: TypeError: null is not an object (evaluating 'backend.connections')
Here is a snippet of my code:
it('Test Search', () => {
backend.connections.subscribe((connection: MockConnection) => {
let options = new ResponseOptions({ body: JSON.stringify(searchData) });
connection.mockRespond(new Response(options)); });
component.ngOnInit();
component.searchTerm = "test";
component.getData();
expect(component.data.length).toBeGreaterThan(0); });
I tried to add the SearchModule to imports of BeforeEach (SearchComponent declared in that SearchModule). Got another error:
"Error: Type SearchComponent is part of the declarations of 2 modules: SearchModule and DynamicTestModule! Please consider moving SearchComponent to a higher mo dule that imports SearchModule and DynamicTestModule. You can also create a new NgModule that exports and includes PolicyPortalComponent then import that NgModule in SearchModule and DynamicTestModule. (line 16032)"
Please advise.
(I am fairly new to Jasmine and Karma)
TIA,
Oleg