Karma测试运行器中的全局变量

编程入门 行业动态 更新时间:2024-10-24 18:23:32
本文介绍了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测试运行器中的全局变量

本文发布于:2023-10-29 10:19:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539437.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:器中   全局变量   测试   Karma

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!