Angular 2 Http testing multiple connections : <p>Can anyone help me with testing Http requests in Angular 2. I have a service that gets a stream from two http requests. How do I mock this behaviour in my test?</p>

<pre><code>loadData() {
    return Observable.forkJoin(
        this.http.get('file1.json').map((res:Response) =&gt; res.json()),
        this.http.get('file2.json').map((res:Response) =&gt; res.json())
    ).map(data =&gt; {
        return {
            x: data[0],
            y: data[1]
        }
    });
}
</code></pre>

<p>Here is my test code, I have tried to use an array of connections but I get an error message saying "Failed: Connection has already been resolved". I have left the body of the connections blank to avoid exposing sensitive data. </p>

<pre><code>describe('Test Load Init Data', () =&gt; {
    it('should load Menu Zones and Menu Sections',
        inject([XHRBackend, AppInitService], (mockBackend, appInitService) =&gt; {
            console.log('Lets do some testing');

            //first we register a mock response
            mockBackend.connections.subscribe(
                (connection:MockConnection) =&gt; {
                    return [
                        connection.mockRespond(new Response(
                            new ResponseOptions({
                                body: []
                            })
                        )),
                        connection.mockRespond(new Response(
                            new ResponseOptions({
                                body: []
                            })
                        ))
                    ];
                });

            appInitService.loadData().subscribe(data =&gt; {
                expect(data.x.length).toBeGreaterThan(0);
                expect(data.y.length).toBeGreaterThan(0);
            });
        }));
});
</code></pre>
