问题
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