未知的提供的CookieStore [英] Unknown provider CookieStore

查看:175
本文介绍了未知的提供的CookieStore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有服务,我想用$的CookieStore模块。它工作正常,但是当单元测试它打破,并给出了错误:$ cookieStoreProvider< - $&CookieStore的LT; - filtersService

这项服务看起来是这样的:

  serviceModule.factory('filtersService',['$ rootScope','$的位置,$的CookieStore',函数($ rootScope,$位置$的CookieStore){
    返回{
        getFilters:功能(){...}
}

和单元测试服务是这样的:

 描述('filtersService测试,函数(){
VAR filtersService;
beforeEach(模块('App.services'));beforeEach(注(功能(filtersService,urlService,$位置){    filtersService = filtersService;
    urlService = urlService;
}));它('考什么',注入(功能(filtersService,$位置){
    filtersService.getFilters();
   期待(...什么...)
}));
});

我已经包含在业力测试文件角​​饼干。

任何想法,为什么code运行时的作品,但单元测试失败了呢?

更新:

 噶配置文件:
//噶配置
//生成在Sun 2013年5月12日16时57分21秒GMT + 0200(CEST)
//基本路径,将用于解析文件和排除
基本路径='../';
//的文件/目录模式在浏览器中加载
文件= [
  茉莉,
  JASMINE_ADAPTER,
  测试/人缘/ jQuery的-1.9.1.min.js',
  应用程序/资产/ Java脚本/糖1.3.9.min.js',
  应用程序/资产/ Java脚本/ angular.js',
  应用程序/资产/ Java脚本/角 - * JS',
  应用程序/资产/ JavaScript的/ UI的引导,第三方物流企业-0.4.0.min.js',
  应用程序/资产/ Java脚本/ services.js',
  测试/人缘/ lib目录/角/角mocks.js',
  测试/人缘/单位/ * / *。JS
];
//文件的列表中排除
排除= [];
//测试结果记者使用
//可能的值:'点','进步','的JUnit
记者= ['进步'];
// Web服务器端口
端口= 9876;
// CLI端口亚军
runnerPort = 9100;
//使输出/禁止的颜色(记者和日志)
颜色= TRUE;
//日志记录级别
//可能的值:LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
LOGLEVEL = LOG_INFO;
//启用/禁用看文件和执行测试,只要任何文件更改
autoWatch =真;
//启动这些浏览器,目前市面上:
// - 镀铬
// - ChromeCanary
// - 火狐
// - 歌剧
// - 野生动物园(仅限Mac)
// - PhantomJS
// - IE(仅限于Windows)
浏览器= ['铬'];
//如果浏览器不给出超时[毫秒]捕捉,杀死它
captureTimeout = 60000;
//持续集成模式
//如果是真的,它捕获的浏览器,运行测试和退出
singleRun = FALSE;


解决方案

从上面的意见,似乎对ngCookies依赖一个单独的模块中声明。

要解决这个问题尝试你的服务模块中声明它:

  VAR serviceModule = angular.app('App.services',['ngCookies']);

这是解决这个问题的推荐方法。

如果由于某种原因,你不能改变serviceModule定义,你也可以再次在单元测试中声明它:

  beforeEach(模块('ngCookies','App.services'));

不过,我会建议你改变它在code碱基让你serviceModule并不取决于你的主要应用模块上它才能正常工作。

I am having service where I want to use the $cookieStore module. It works fine, but when unit testing it breaks, and gives the error: "$cookieStoreProvider <- $cookieStore <- filtersService".

The service looks like this:

serviceModule.factory('filtersService', ['$rootScope', '$location', '$cookieStore', function($rootScope, $location, $cookieStore){
    return {
        getFilters: function(){...}
}

And the unit test service looks like this:

describe('filtersService tests', function(){
var filtersService;
beforeEach(module('App.services'));

beforeEach(inject(function(filtersService, urlService, $location){

    filtersService = filtersService;
    urlService = urlService;
}));

it('test something', inject(function(filtersService, $location){
    filtersService.getFilters();
   expect(...something...)
}));
});

I have included angular-cookies in the karma test file.

Any idea why the code works when running, but unittests fails?

Update:

Karma Config File:
// Karma configuration
// Generated on Sun May 12 2013 16:57:21 GMT+0200 (CEST)


// base path, that will be used to resolve files and exclude
basePath = '../';


// list of files / patterns to load in the browser
files = [
  JASMINE,
  JASMINE_ADAPTER,
  'test/karma/jquery-1.9.1.min.js',
  'app/assets/javascripts/sugar-1.3.9.min.js',
  'app/assets/javascripts/angular.js',
  'app/assets/javascripts/angular-*.js',
  'app/assets/javascripts/ui-bootstrap-tpls-0.4.0.min.js',
  'app/assets/javascripts/services.js',
  'test/karma/lib/angular/angular-mocks.js',
  'test/karma/unit/*/*.js'
];


// list of files to exclude
exclude = [

];


// test results reporter to use
// possible values: 'dots', 'progress', 'junit'
reporters = ['progress'];


// web server port
port = 9876;


// cli runner port
runnerPort = 9100;


// enable / disable colors in the output (reporters and logs)
colors = true;


// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel = LOG_INFO;


// enable / disable watching file and executing tests whenever any file changes
autoWatch = true;


// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers = ['Chrome'];


// If browser does not capture in given timeout [ms], kill it
captureTimeout = 60000;


// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun = false;

解决方案

From the comments above, it seems the dependency on 'ngCookies' is declared in a seperate module.

To fix this try declaring it in your service module:

var serviceModule = angular.app('App.services', ['ngCookies']);

This is the recommended way of fixing this.

If, for some reason, you could not change the serviceModule definition, you could also declare it again in your unit tests:

beforeEach(module('ngCookies','App.services'));

However i would recommend you change it in your code base so your serviceModule does not depend on your main App module for it to function properly.

这篇关于未知的提供的CookieStore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆