本文介绍了在茉莉花测试中更改全局变量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们在React应用程序中将这样的全局变量用于茉莉花测试批次.
We use global variables like this for a jasmine test batch in our react app.
global.serverVars = {
language: 'en-us',
context: 'testing',
};
在测试不同语言的规范之一中,我想将global.serverVars.language
的值更改为nl-nl
In one of the Spec which tests different languages, I want to change value of global.serverVars.language
to nl-nl
我不确定如何实现这一目标.任何建议都会有所帮助.我的意思是,即时更改全局变量值是一种好的做法,还是有更好的方法?
I am not sure how to achieve that. Any suggestion would be helpful.I mean, is it good practice to change global variable values on the fly or there is better approach?
推荐答案
为什么在执行测试用例之前不使用beforeEach
或before
方法调用全局变量?
Why don't you call your global variable in beforeEach
or before
Method before executing the test-cases?.
(function() {
describe('Canvas Actions', function() {
beforeEach(function () {
global.serverVars.language: 'nl-nl',
});
});
})()
这篇关于在茉莉花测试中更改全局变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!