AngularJS 1.2 ngRoute单元测试错误 [英] AngularJS 1.2 ngRoute unit test error

查看:115
本文介绍了AngularJS 1.2 ngRoute单元测试错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我升级到V1.2 angularjs,现在我的单元测试,因为ngRoute的失败。我在这里 http://docs.angularjs.org/api/ngRoute 跟着变化,包括在我的index.html文件新的脚本,以及加载模块和我的应用程序正常工作:

- index.html的

 <脚本SRC =bower_components /角/ angular.js>< / SCRIPT>
<脚本SRC =bower_components /角路由/角route.js>< / SCRIPT>

- app.js

  VAR socketwizModule = angular.module('socketwizApp',['ngRoute']);

但我的测试中失败,出现以下<一个href=\"http://docs.angularjs.org/error/%24injector%3amodulerr?p0=ngRoute&p1=Error%3a%20%5B%24injector%3anomod%5D%20Module%20%27ngRoute%27%20is%20not%20available!%20You%20either%20misspelled%20the%20module%20name%20or%20forgot%20to%20load%20it.%20If%20registering%20a%20module%20ensure%20that%20you%20specify%20the%20dependencies%20as%20the%20second%20argument.%0Ahttp%3a%2F%2Ferrors.angularjs.org%2F1.2.0-rc.2%2F%24injector%2Fnomod%3Fp0%3DngRoute%0A%20%20%20%20at%20http%3a%2F%2Fsocketwiz:8080%2Fbase%2Fapp%2Fbower_components%2Fangular%2Fangular.js%3F1378401706000:78:12%0A%20%20%20%20at%20http%3a%2F%2Fsocketwiz:8080%2Fbase%2Fapp%2Fbower_components%2Fangular%2Fangular.js%3F1378401706000:1330:36%0A%20%20%20%20at%20ensure%20%28http%3a%2F%2Fsocketwiz:8080%2Fbase%2Fapp%2Fbower_components%2Fangular%2Fangular.js%3F1378401706000:1268:38%29%0A%20%20%20%20at%20module%20%28http%3a%2F%2Fsocketwiz:8080%2Fbase%2Fapp%2Fbower_components%2Fangular%2Fangular.js%3F1378401706000:1328:14%29%0A%20%20%20%20at%20http%3a%2F%2Fsocketwiz:8080%2Fbase%2Fapp%2Fbower_components%2Fangular%2Fangular.js%3F1378401706000:3071:26%0A%20%20%20%20at%20Array.forEach%20%28native%29%0A%20%20%20%20at%20forEach%20%28http%3a%2F%2Fsocketwiz:8080%2Fbase%2Fapp%2Fbower_components%2Fangular%2Fangular.js%3F1378401706000:224:11%29%0A%20%20%20%20at%20loadModules%20%28http%3a%2F%2Fsocketwiz:8080%2Fbase%2Fapp%2Fbower_components%2Fangular%2Fangular.js%3F1378401706000:3065:5%29%0A%20%20%20%20at%20http%3a%2F%2Fsocketwiz:8080%2Fbase%2Fapp%2Fbower_components%2Fangular%2Fangular.js%3F1378401706000:3072:40%0A%20%20%20%20at%20Array.forEach%20%28native%29\"相对=nofollow>错误。

我尝试了以下几件事情,但似乎没有任何工作,任何想法?

  beforeEach(模块('socketwizApp',['ngRoute']));

  beforeEach(模块('ngRoute'));
beforeEach(模块('socketwizApp'));


解决方案

您说您固定的code,但你没有说你固定你的测试。假设你使用噶单元测试(像我一样),你确定你的conf.js文件包含在这里?

  //的文件/目录模式在浏览器中加载
文件:
  应用程序/组件/角/ angular.js',
  应用程序/组件/角嘲笑/角mocks.js',
  应用程序/脚本/ ** / *。JS',
  测试/ ** / * Spec.js
]

由于如果没有的话也不会提供给你的单元测试,因为(再次,如果他们像我这样的),他们不使用的index.html获取JavaScript的列表中包含它。

I upgraded to angularjs v1.2 and now my unit tests are failing because of ngRoute. I followed the changes here http://docs.angularjs.org/api/ngRoute and included the new script in my index.html file as well as loading the module and my app works fine:

--index.html

<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>

--app.js

var socketwizModule = angular.module('socketwizApp', ['ngRoute']);

But my tests fail with the following error.

I tried the following couple of things but nothing seems to work, any ideas?

beforeEach(module('socketwizApp', ['ngRoute']));

And

beforeEach(module('ngRoute'));
beforeEach(module('socketwizApp'));

解决方案

You said you fixed your code but you didn't say that you fixed your tests. Assuming that you use Karma for unit tests (as I do), did you make sure that your conf.js file includes it here?

// list of files / patterns to load in the browser
files: [
  'app/components/angular/angular.js',
  'app/components/angular-mocks/angular-mocks.js',
  'app/scripts/**/*.js',
  'test/**/*Spec.js'
],

Because if not then it won't be available to your unit tests because (again, if they're like mine) they don't use the index.html to get the list of JavaScript to include.

这篇关于AngularJS 1.2 ngRoute单元测试错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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