当我运行下面的代码时,我得到下面的错误。结果消息:
错误:意外请求: GET /api/movies
代码将在gist链接中更新。我只是想知道我是否做错了什么,或者需要配置其他东西。
https://gist.github.com/rahulsahay19/041ca130d187e2a6009e
谢谢,Rahul
发布于 2015-02-15 01:31:24
解决了。我将respond封装在一个对象中,然后返回相同的对象。
/// <reference path="../scripts/jasmine.js" />
/// <reference path="../../moviereview.web/scripts/angular.min.js" />
/// <reference path="../../moviereview.web/scripts/ui-bootstrap-tpls.min.js" />
/// <reference path="../../moviereview.web/scripts/angular-route.min.js" />
/// <reference path="../../moviereview.web/scripts/angular-mocks.js" />
/// <reference path="../../moviereview.web/js/homeindex.js" />
/// <reference path="../../moviereview.web/js/movie-review-edit.js" />
describe("home-Index Tests-->", function () {
beforeEach(function () {
module("homeIndex");
});
//to test individual bits and bytes inside the home-Index
describe("dataService-->", function () {
it("can load movies", inject(function (dataService) {
//for the 1st Run
expect(dataService.movies.length).toEqual(0);
}));
});
//$httpbackend service
var $httpBackend;
var url = '/api/movies';
var fakedMoviesResponse=[{
Id: 1,
MovieName: "Godzilla",
DirectorName: "Gareth Edwards",
ReleaseYear: "2014",
NoOfReviews: 6
},
{
Id: 3,
MovieName: "Titanic",
DirectorName: "James Cameron",
ReleaseYear: "1997",
NoOfReviews: 3
},
{
Id: 4,
MovieName: "Die Another Day",
DirectorName: "Lee Tamahori",
ReleaseYear: "2002",
NoOfReviews: 0
},
{
Id: 7,
MovieName: "Taken 3",
DirectorName: "Olivier Megaton",
ReleaseYear: "2014",
NoOfReviews: 0
},
{
Id: 9,
MovieName: "Top Gun",
DirectorName: "Tony Scott",
ReleaseYear: "1986",
NoOfReviews: 0
}
];
beforeEach(inject(function ($injector) {
$httpBackend = $injector.get("$httpBackend");
$httpBackend.whenGET(url)
.respond(fakedMoviesResponse);
}));
afterEach(function () {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});
//test the backend call
describe("Testing Movies GET Call-->", function () {
it("Loaded Movies", inject(function (dataService) {
$httpBackend.expectGET(url);
dataService.getMovies();
$httpBackend.flush();
expect(dataService.movies.length).toEqual(5);
}));
});
})
https://stackoverflow.com/questions/28517903
复制相似问题