如何将jquery添加到jasmine / angularjs单元测试中 [英] How to add jquery to jasmine/angularjs unittests

查看:69
本文介绍了如何将jquery添加到jasmine / angularjs单元测试中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在plain angular.js代码上构建的项目。我们用茉莉花创造单元测试。但是现在我们需要获取一些第三方组件(来自Angular-Bootstrap的一些指令),这里面也是纯粹的angular.js,但是为了测试那些组件,使用了一些jQuery代码和方法调用。现在很多第三方测试失败了,例如
[object]没有方法'触发'和类似的东西

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包含在我的测试中,以使第三方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单元测试中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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