如何将 jquery 添加到 jasmine/angularjs unittests [英] How to add jquery to jasmine/angularjs unittests
问题描述
我有一个基于普通 angular.js 代码的项目.我们用茉莉花创建单元测试.但是现在我们需要获取一些 3rd 方组件(一些来自 Angular-Bootstrap 的指令),它们也是纯 angular.js 内部,但是为了测试这些组件,使用了一些 jQuery 代码和方法调用.现在很多 3rd 方测试都失败了,但像[object] 没有方法 'trigger'
之类的东西
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
所以我的问题是如何将 jquery 包含到我的测试中,以使 3rd 方 unitests 有效.我使用 Karma 进行测试.
So my question is how to include jquery to my tests, to make 3rd party unitests valid. I run tests with Karma.
推荐答案
只需将 jquery.js 作为第一项包含在文件数组中的 Karma 配置中.
Just include jquery.js to Karma's config in files array as the first item.
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
});
};
这篇关于如何将 jquery 添加到 jasmine/angularjs unittests的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!