Null backend connection in Angular4 unit test <https://www.reddit.com/r/Angular2/comments/77jwe3/null_backend_connection_in_angular4_unit_test/> self.Angular2 <https://www.reddit.com/r/Angular2/>
Submitted a minute ago by olegkon <https://www.reddit.com/user/olegkon> 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 -- You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
