How can I interpolate the test.each table with variables defined elsewhere? In the following example I am trying to use someData defined in beforeAll.
Here's the Jest functionality I am using: https://jestjs.io/docs/api#testeachtablename-fn-timeout
Follows a code snippet of what I am trying to do:
const someCall = async () => {
return { field: "lalala" };
};
describe(`Some test suite`, () => {
let someData;
beforeAll(async () => {
const callOutput = await someCall();
someData = callOutput.field;
});
beforeEach(async () => {});
it.each`
data | moreData
${{ name: "Jack" }} | ${"foo"}
${someData} | ${"bar"}
`("Tests here...", async ({ data, moreData }) => {
console.log("Data:", data); // <---- data is undefined for the second test
console.log("More data:", moreData);
});
});
The issue is that in the second test someData is undefined rather than having the value "lalala".