在Vojta的
project关于测试指令这段代码有什么作用?
// load the tabs code beforeEach(module('tabs'));
它说它加载标签代码,但为什么?接下来是不是已经定义了标签模块?
var tabs = angular.module('tabs',[]);
有人可以给角度测试中应该加载的原因和方法做一个很好的解释吗?
beforeEach(module('utils')) ;
我收到此错误:
TypeError: Property 'module' of object [object Object] is not a function
当我尝试加载这样的模板时
beforeEach(module('templates/loadingBar.html'));
我收到此错误:
Error: No module: templates/loadingBar.html
我对整个过程感到困惑.
谢谢你的帮助……
解决方法
您列出的代码
var tabs = angular.module('tabs',[]);
创建选项卡模块,但是为了加载它,您可能会在DOM中的元素上添加类似ng-app =“tabs”的内容.这指示Angular加载tabsmodule并使其定义可用于应用程序用于解析依赖关系的injector. (有关更多信息,请参阅Bootstrap guide.)
在您的测试中,没有ng-app指令来初始化注入器或加载模块;模块功能(exists on angular.mock
from the angular-mocks.js
file)在测试中为您完成此操作.如果您使用Karma Jasmine或Mocha适配器进行测试,它会使模块可用,否则您可能需要调用angular.mock.module.