changing global variable values in jasmine test

拟墨画扇 提交于 2019-12-11 04:59:02

问题


We use global variables like this for a jasmine test batch in our react app.

global.serverVars = {
language: 'en-us',
context: 'testing',

};

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?


回答1:


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',
    });
  });
})()


来源:https://stackoverflow.com/questions/38953792/changing-global-variable-values-in-jasmine-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!