Update: I tried to put some console outputs there:
 it seems that the second beforeEach block which supposed to inject 
MockBackend (see code snippet below) is not getting executed.
 The first beforeEach block contains TestBed.configureTestingModule, so 
must be there. 
Is it normal to have 2 beforeEach blocks? 
Maybe one should explicitly call another? 
Please advise.      
let backend: MockBackend = null; 
and will get injected: 
beforeEach(inject([..., MockBackend], (..., mockBackend: MockBackend) => { 
backend=mockbackend; }));


On Friday, October 20, 2017 at 12:40:22 AM UTC-4, OlegKon wrote:
>
> 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.

Reply via email to