我有一个在plain angular.js代码上构建的项目。我们用茉莉花创造单元测试。但是现在我们需要获取一些第三方组件(来自Angular-Bootstrap的一些指令),这里面也是纯粹的angular.js,但是为了测试那些组件,使用了一些jQuery代码和方法调用。现在很多第三方测试都失败了,例如
[object] had no method 'trigger'
和类似的东西
所以我的问题是如何将jquery包含在我的测试中,以使第三方unitests有效。 我用Karma进行测试。
答案 0 :(得分:31)
只需将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
});
};