JSFiddle - React, Tailwind, and code Playground
HTML
<script src="//searls.github.com/jasmine-all/jasmine-all-min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular-mocks.js"></script>
JavaScript
// Bootstrap app
angular
.module('App', [])
.config(configureApp)
.service('Test', TestService);
// Do the testing
describe('Do the testing', () => {
var Test;
var $httpBackend;
beforeEach(module('App'));
beforeEach(inject((_Test_, _$httpBackend_) => {
Test = _Test_;
$httpBackend = _$httpBackend_;
$httpBackend
.whenGET('/firstCall.json')
.respond(200, { items: [1, 2, 3] });
$httpBackend
.whenGET('/secondCall/1.json')
.respond(200, { items: [4, 5, 6] });
}));
it('should work', () => {
var result = null;
Test
.doubleHttpCall()
.then(data => result = data);
$httpBackend.flush();
debugger;
expect(result).toBe(4);
})
});
//////////////////
function TestService($http)
{
return {
doubleHttpCall: doubleHttpCall
}
function doubleHttpCall()
{
return $http.get('/firstCall.json')
.then((response) => $http.get('/secondCall/' + response.data.items[0] + '.json'))
.then((response) => response.data.items[0]);
}
}
TestService.$inject = ['$http'];
function configureApp($httpProvider)
{
$httpProvider.useApplyAsync(true);
}
configureApp.$inject = ['$httpProvider'];