Jasmine:在测试中添加Lodash [英] Jasmine: Adding Lodash to Testing

查看:221
本文介绍了Jasmine:在测试中添加Lodash的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序/组件中使用lodash。 Jasmine抱怨:

I'm using lodash in my application/component. Jasmine is complaining:

失败:无法读取未定义的属性'eq'

Failed: Cannot read property 'eq' of undefined

我添加了,lodash到我的karma.conf

I've added, lodash to my karma.conf

例如:{pattern:'。/ node_modules / lodash / lodash.min.js',包括:true,watched:false}

such as:{ pattern: './node_modules/lodash/lodash.min.js', included: true, watched: false }

仍然有问题,包含lodash的正确方法是什么?

Still getting the issue, what is the correct way of including lodash?

推荐答案

<我通过将这些行添加到main.ts解决了这个问题:

I solved this problem by adding these lines to "main.ts":

//...

import _ from 'lodash';

declare global {
  const _: _.LoDashStatic;
}

//...

此外,我将lodash添加到karma.conf.js:

Also, I added lodash to karma.conf.js:

module.exports = function(config) {
    config.set({
          basePath: '',
          frameworks: ['jasmine', '@angular/cli'],
          files: [
            'node_modules/lodash/lodash.js'
          ],
          //...

这篇关于Jasmine:在测试中添加Lodash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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