我遇到了一些麻烦,单元测试一个简单的用户服务,它暴露了两个功能。 测试和服务如下。 每当我运行测试时,我都会收到以下错误..
PhantomJS 2.1.1 (Mac OS X 0.0.0) User Service should contain a UserService FAILED
Error: [$injector:unpr] Unknown provider: UserProvider <- User
http://errors.angularjs.org/1.5.6/$injector/unpr?p0=UserProvider%20%3C-%20User (line 4501)
服务
angular.module('y2yApp').service('User', function($http) {
this.profile = function() {
return $http({
method: 'GET',
url: config.MW_URL + '/profile'
}).then(function(response) {
return {
err: null,
data: response.data
};
}, function(response) {
return {
err: response.data,
data: null
};
});
};
this.update = function(userInfo) {
return $http({
method: 'POST',
url: config.MW_URL + '/profile',
data : userInfo
});
};
});
测试
describe('User Service', function() {
beforeEach(function() {
angular.module('y2yApp');
});
it('should contain a UserService',inject(['User',function(User) {
console.log(User);
expect(User).not.to.equal(null);
}]));
});
如果这个测试运行,并且我能够正确获取用户服务实例,我可以继续编写其余的测试,但由于某种原因它无法正常工作。有人可以帮我解决这个问题,并对我在这里犯错的事情有所了解......