本文介绍了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测试运行器中的全局变量
发布评论