I'm trying to use angular-mocks and it is not working
every time i run the app it shows this error in the console.
Error: Unexpected request: GET components/hotel/hotelListView.html No more request expected
at $httpBackend (angular-mocks.js:1211) at sendReq (angular.js:10232) at serverRequest (angular.js:9944) at processQueue (angular.js:14454) at angular.js:14470 at Scope.$eval (angular.js:15719) at Scope.$digest (angular.js:15530) at Scope.$apply (angular.js:15824) at bootstrapApply (angular.js:1628) at Object.invoke (angular.js:4426)
This is my app.js
(function(){
"use strict";
var app = angular.module("WebApp", [
"common.services",
"ui.router",
"hotelResourceMock"
]);
}());
routes.js
(function () {
"use strict";
angular
.module("WebApp")
.config(["$stateProvider",
"$urlRouterProvider",
function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise("/");
$stateProvider
//Home
.state("home", {
url: "/",
templateUrl: "components/home/homeView.html"
})
//Hotel Availability
.state("/hotelsAvail", {
url: "/hotelsAvail",
templateUrl: "components/hotel/hotelListView.html",
controller: "HotelListController as vm"
})
//Hotel Detail
.state("hotelDetail", {
url: "/hotelDetail",
templateUrl: "components/hotel/hotelDetailView.html",
controller: "hotelDetailController as vm"
})
}]);
}());
common.services.js
(function() {
"use strict";
angular.module("common.services",
["ngResource"]);
}());
hotelResource.js
(function() {
"use strict";
angular
.module("common.services")
.factory("hotelResource",
["$resource",
hotelResource]);
function hotelResource($resource){
return $resource("/api/hotels/:hotelCode");
}
}());
hotelResourceMock.js
(function() {
"use strict";
var app = angular
.module("hotelResourceMock", [
"ngMockE2E"]);
app.run(function ($httpBackend) {
var hotels = [
{
"hotelCode": 1,
"name": "Mabely Grand Hotel",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum nec semper lectus. Suspendisse placerat enim mauris, eget lobortis nisi egestas et. Donec elementum metus et mi aliquam eleifend. Suspendisse volutpat egestas rhoncus.",
"price": 38.00,
"image_url": "",
"stars": 5
},
{
"hotelCode": 2,
"name": "Amic Gala",
"description": "bla bla bla,
"price": 45.00,
"image_url": "",
"stars": 4
}
];
var hotelUrl = "/api/hotels";
$httpBackend.whenGET(hotelUrl).respond(hotels);
$httpBackend.whenGET(/app/).passThrough();
});
}());
hotelListController.js
(function () {
"use strict";
angular.module("WebApp")
.controller("HotelListController", [
"hotelResource",
HotelListController]);
function HotelListController(hotelResource) {
var vm = this;
hotelResource.query(function (data) {
vm.hotels = data;
});
}
}());
Aucun commentaire:
Enregistrer un commentaire