我是angular.js的新手。但我想用一些单元测试编写代码。 如何在karma / jasmine中注入并测试$ http get方法? 下面的代码似乎不起作用。我使用的是Angular 1.4.7。
describe('Controllers', function(){ //describe your object type
var scope
var $http, $q;
beforeEach(module('MyApp')); //load module
beforeEach(inject(function(_$http_, _$q_) {
$http = _$http_;
$q = _$q_;
}));
describe('myctrl',function(){ //describe your app name
beforeEach(inject(function($controller, $rootScope){ //instantiate controller using $controller service
scope = $rootScope.$new
myctrl = $controller('myctrl',{$scope: scope, $http: $http});
}));
it('Message should be ok', function(){ //write tests
expect(scope.messge).toBe('ok'); //pass
});
});
});
infile = open("new.csv", "r")
data = []
for line in infile:
cols = line.split(",")
Oposition = cols[0]
Winner = cols[1]
Margin = cols[2]
Ground = cols[3]
Year = cols[4]
pair = (Oposition, Winner, Margin, Ground, Year)
data.append(pair)
infile.close()