用"declare var"测试组件. [英] Test component with "declare var"

查看:85
本文介绍了用"declare var"测试组件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的angular2应用中,我的js文件"connection.conf.js"带有var:

In my angular2 app I have js file "connection.conf.js" with var:

var appTypeConf = "example-app";

组件使用"connection.conf.js"中的变量:

Component uses the variable from "connection.conf.js":

declare var appTypeConf: string;

export class Component {
  public appType = appTypeConf;
}

它在我的应用程序中完全起作用,但是当我使用业力测试应用程序时, 我收到错误消息:

it works corectly in my app, but when I test application with karma, I receive a error:

ReferenceError: Can't find variable: appTypeConf (line 9)

如何在组件规范文件中核心声明一个变量?

How to corectly declare a variable in the component spec file?

推荐答案

我找到了解决方案,我必须将connection.conf.js路径添加到karma.conf.js中的文件数组

I found the solution, I had to add connection.conf.js path to files array in karma.conf.js

var files = [
  // ***
  'app/connection.conf.js'
]

这篇关于用"declare var"测试组件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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