I have a scenario where one of my program files has an IFFE and wants to access a variable which is being set in a setupTest beforeAll
block.
For example I have a component.js file which has an IFFE
const { getSandbox } = require("../env");
(async function () {
const sandbox = getSandbox();
const { pluralize } = sandbox;
console.log(pluralize("word"));
})();
module.exports = {
summingComponent: function (num1, num2, word) {
return num1 + num2 + " " + getSandbox().pluralize(word);
},
};
This above code is executed before I call setSandbox
in the beforeAll
// setupTests.js
const sandbox = require("./__mocks__/sandbox");
const { setSandbox } = require("./env");
beforeAll(() => {
setSandbox(sandbox)
});
The tests are breaking even before the tests start their execution, as the IFFE is being executed before the beforeAll
block. How do I fix this. Can’t find a way.
I have created a ReplIt to reproduce this problem, this is mimicing my actual project.
https://replit.com/join/dnrlauoevi-mohammaddanishs