javascript 如何将 jquery 添加到 jasmine/angularjs unittests
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19073570/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add jquery to jasmine/angularjs unittests
提问by silent_coder
I have a project which is builded on plain angular.js code. We creates unittest with jasmine. But now we need to grab some 3rd party components (some directives from Angular-Bootstrap), which is also pure angular.js inside, but for testing that components some jQuery code and methods calls used. And now a lot of 3rd party tests failed with exception like
[object] had no method 'trigger'
and stuff like that
我有一个基于普通 angular.js 代码的项目。我们用茉莉花创建单元测试。但是现在我们需要获取一些 3rd 方组件(一些来自 Angular-Bootstrap 的指令),它们也是纯 angular.js 内部,但是为了测试这些组件,使用了一些 jQuery 代码和方法调用。现在很多 3rd 方测试都以异常之类的[object] had no method 'trigger'
东西失败了
So my question is how to include jquery to my tests, to make 3rd party unitests valid. I run tests with Karma.
所以我的问题是如何将 jquery 包含到我的测试中,以使 3rd 方 unitests 有效。我用 Karma 运行测试。
回答by Alexander Puchkov
Just include jquery.js to Karma's config in files array as the first item.
只需将 jquery.js 作为第一项包含在文件数组中的 Karma 配置中。
module.exports = function(config) {
config.set({
// list of files / patterns to load in the browser
files: [
'path/to/jquery.js',
'path/to/angular.js'
//..rest files
],
//rest karma options
});
};