admin管理员组文章数量:1356554
I'm writing a test for the following Angular.js service:
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);
};
// ..
}
The test case is as follows:
/**
* 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();
});
});
This looks to be about as text-book as it gets. Unfortunately, I'm getting the following error:
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
.4.1/$injector/unpr?p0=wpServiceProvider%20%3C-%20wpService
at /Users/jdolan/Coding/tuuli-syndicate/bower_ponents/angular/angular.js:68:12
My karma.config.js includes the modules as well as angular-mocks.js
:
// list of files / patterns to load in the browser
files : [ 'bower_ponents/jquery/dist/jquery.js',
'bower_ponents/lodash/lodash.js',
'bower_ponents/moment/moment.js',
'bower_ponents/x2js/xml2json.js',
'bower_ponents/aws-sdk/dist/aws-sdk.js',
'bower_ponents/angular/angular.js',
'bower_ponents/angular-route/angular-route.js',
'bower_ponents/angular-mocks/angular-mocks.js',
'app/**/*.js',
'tests/**/*.js' ],
I'm using Angular 1.4.1, Karma 0.12.36.
I'm writing a test for the following Angular.js service:
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);
};
// ..
}
The test case is as follows:
/**
* 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();
});
});
This looks to be about as text-book as it gets. Unfortunately, I'm getting the following error:
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/1.4.1/$injector/unpr?p0=wpServiceProvider%20%3C-%20wpService
at /Users/jdolan/Coding/tuuli-syndicate/bower_ponents/angular/angular.js:68:12
My karma.config.js includes the modules as well as angular-mocks.js
:
// list of files / patterns to load in the browser
files : [ 'bower_ponents/jquery/dist/jquery.js',
'bower_ponents/lodash/lodash.js',
'bower_ponents/moment/moment.js',
'bower_ponents/x2js/xml2json.js',
'bower_ponents/aws-sdk/dist/aws-sdk.js',
'bower_ponents/angular/angular.js',
'bower_ponents/angular-route/angular-route.js',
'bower_ponents/angular-mocks/angular-mocks.js',
'app/**/*.js',
'tests/**/*.js' ],
I'm using Angular 1.4.1, Karma 0.12.36.
Share Improve this question asked Jun 23, 2015 at 23:06 jdolanjdolan 5895 silver badges15 bronze badges1 Answer
Reset to default 11Read the angular-mocks example here closely.
The angular.module()
function returns an actual angular module, while module()
is short for angular.mock.module()
. Replace this line in your code and you should be all set:
beforeEach(module('wp'));
本文标签: javascriptAngularjsKarmaJasmine Unknown provider for serviceStack Overflow
版权声明:本文标题:javascript - Angular.js + Karma + Jasmine: Unknown provider for service - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743965170a2569752.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论