本文介紹了Karma 測試運行程序中的全局變量的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
限時送ChatGPT賬號..
我在我的主模板中定義了一個全局變量,我用它來存儲來自后端的信息位,例如環(huán)境上下文路徑.我無法在服務(wù)中移動該變量.
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'
],
這篇關(guān)于Karma 測試運行程序中的全局變量的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!