Karma测试运行器中的全局变量 [英] Global variables in Karma test runner

查看:174
本文介绍了Karma测试运行器中的全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的主模板中定义了一个全局变量,我用它来存储来自后端的信息位,例如环境上下文路径。我不能在服务中移动该变量。

I have a global variable defined in my main template, which I use to store information bits from the back end, such as the environment context path. I can't move that variable inside a service.

当我运行单元测试时,如何将该变量公开给Karma?

How can I expose that variable to Karma when I run the unit tests?

推荐答案

您可以在测试文件中声明该全局变量:

You either declare that global variable within your test file:

var global = "something";

describe('Your test suit', function() {
...
});

或添加一个Javascript文件,将其定义到 karma.conf.js file:

or add a Javascript file where it's defined to your karma.conf.js file:

// list of files / patterns to load in the browser
files: [
   ...,
   'file-containing-the-global-variable.js'
],

这篇关于Karma测试运行器中的全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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