1
这是我的代码,我得到以下错误,无法弄清楚。无法读取undefined属性'expectGET'
describe('Myctrl', function() {
var $httpBackend, scope, createController, authRequestHandler;
// Set up the module
beforeEach(module('myApp'));
alert("Hello there!");
beforeEach(inject(function ($injector) {
// Set up the mock http service responses
alert("Hello there!");
$httpBackend = $injector.get('$httpBackend');
// backend definition common for all tests
alert("Hello there!");
authRequestHandler = $httpBackend.when('GET', 'http://www.w3schools.com/angular/customers.php')
.respond(true);
// Get hold of a scope (i.e. the root scope)
$rootScope = $injector.get('$rootScope');
// The $controller service is used to create instances of controllers
var $controller = $injector.get('$controller');
createController = function() {
return $controller('Myctrl', {'$scope' : scope});
};
})
);
/*
afterEach(function() {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});*/
it('should fetch authentication token', function() {
//create expectation
$httpBackend.expectGET('http://www.w3schools.com/angular/customers.php');
var controller = createController()
$httpBackend.flush();
expect(scope.names).toBeTruthy(true);
});
});
我尝试了一些不同的东西,但我仍然无法弄清楚什么是错的。这似乎没有错。这种情况下的解决方案是什么?
我加入了角的js和角mock.js但还是错误是一样的\ – NAND
如何包括ngMock模块吗? (module('myApp')); ** with ** beforeEach(module('myApp',['ngMock'])); **会起作用。我会用它修改我的帖子 –
这是行不通的,我试了一下,但仍然收到错误 – NAND