AngularJS Essentials
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Chapter 7<br />
$httpBackend.whenGET("/cars").respond(function (method, url, data,<br />
headers) {<br />
return [500, mockedCars.getCars(), {}];<br />
});<br />
$httpBackend.flush();<br />
expect($scope.message).toBe("Something went wrong!");<br />
});<br />
it("The car should be parked", function () {<br />
$httpBackend.whenGET("/cars").respond(function (method, url, data,<br />
headers) {<br />
return [200, mockedCars.getCars(), {}];<br />
});<br />
$httpBackend.whenPOST("/cars").respond(function (method, url,<br />
data, headers) {<br />
var id = mockedCars.saveCar(angular.fromJson(data));<br />
return [201, mockedCars.getCar(id), {}];<br />
});<br />
$scope.car = {<br />
plate: "AAAA9977",<br />
color: "Blue"<br />
};<br />
$scope.park($scope.car);<br />
$httpBackend.flush();<br />
expect($scope.cars.length).toBe(3);<br />
expect($scope.car).toBeUndefined();<br />
expect($scope.message).toBe("The car was parked successfully!");<br />
});<br />
});<br />
Now, you just need to add the files to the SpecRunner.html file and open it in<br />
your browser:<br />
SpecRunner.html<br />
<br />
<br />
<br />
Jasmine Spec Runner v2.0.0<br />
<br />
<br />
<br />
<br />
[ 139 ]<br />
www.it-ebooks.info