Angular.js+Karma+Jasmine:未知服务提供商
Angular.js + Karma + Jasmine: Unknown provider for service
我正在为以下Angular.js服务编写一个测试:
var module = angular.module('wp', [ 'aws', 'lodash', 'jquery', 'moment', 'wp.model' ]);
/**
* Wordpress service.
*/
module.service('wpService', function(_, $http, $q, $aws, Post) {
var self = this;
/**
* HTTP request.
*/
this.http = function(config) {
var $config = _.clone(config);
if ($config.user && $config.password) {
$config.headers = $config.headers || {};
$config.headers.Authorization = 'Basic ' + btoa($config.user + ':' + $config.password);
}
return $http($config);
};
// ..
}
测试用例如下:
/**
* Unit tests for wpService.
*/
describe('apService', function() {
var wpService;
beforeEach(angular.module('wp'));
beforeEach(inject(function(_wpService_) {
wpService = _wpService_;
}));
it('is defined', function() {
expect(wpService).toBeDefined();
});
});
这看起来就像是一本教科书。不幸的是,我得到了以下错误:
Chrome 43.0.2357 (Mac OS X 10.10.3) apService is defined FAILED
TypeError: queueableFn.fn.call is not a function
Error: [$injector:unpr] Unknown provider: wpServiceProvider <- wpService
http://errors.angularjs.org/1.4.1/$injector/unpr?p0=wpServiceProvider%20%3C-%20wpService
at /Users/jdolan/Coding/tuuli-syndicate/bower_components/angular/angular.js:68:12
我的karma.config.js包括模块以及angular-mocks.js
:
// list of files / patterns to load in the browser
files : [ 'bower_components/jquery/dist/jquery.js',
'bower_components/lodash/lodash.js',
'bower_components/moment/moment.js',
'bower_components/x2js/xml2json.js',
'bower_components/aws-sdk/dist/aws-sdk.js',
'bower_components/angular/angular.js',
'bower_components/angular-route/angular-route.js',
'bower_components/angular-mocks/angular-mocks.js',
'app/**/*.js',
'tests/**/*.js' ],
我使用的是Angular 1.4.1,Karma 0.12.36。
仔细阅读此处的角度模拟示例。
angular.module()
函数返回实际的角度模块,而module()
是angular.mock.module()
的缩写。在你的代码中替换这一行,你应该已经做好了准备:
beforeEach(module('wp'));
相关文章:
- SqlStorage Ionic 2作为服务/提供程序
- AWS Cognito:通过 google 获取“请提供有效的公共提供商”
- 角度模态服务未知提供商
- 选择下拉列表需要在选中时显示提供商的详细信息-无法通过我的脚本显示url
- 如何使用Angular 2服务提供包含指向另一个资源的链接/ids的资源集合
- 从服务提供商 IP 地址获取设备 IP 地址
- JsFiddle:未知提供商:$intervalProvider <- $interval
- (IONIC)错误: [$injector:unpr] 未知提供程序: 数据服务提供程序 <- 数据服务<- 身份验证控
- 工厂和控制器,未知提供商
- ES2015 单例或服务提供商或模块,用于敲除.js组件
- Angular Js:工厂、服务和提供商.何时使用哪个
- 为什么我必须添加尾部'提供商'到服务名称,当我使用es6时
- 如何在AngularJs中设置来自其提供商的服务的依赖关系
- 在AngularJS中,当自定义服务注入到不同的模块时,未知的提供商
- forEach内部提供商服务AngularJS
- 使用Jasmine在AngularJS中测试服务时,未知提供商
- Angular:在模块's的config/run中混合了提供商和自定义服务
- 未知的提供商:userProvider为现有的约曼AngularFire用户服务
- 如何使用angular 1.3将服务注入提供商
- Angular.js+Karma+Jasmine:未知服务提供商