Global variables in Karma test runner(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() {
...
});
或在您的 karma.conf.js 文件中添加一个 Javascript 文件:
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 测试运行程序中的全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Karma 测试运行程序中的全局变量
基础教程推荐
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
