You did forget the closing bracket on the beforeEach() line.
let a;
beforeEach(() => {
a = 'hello';
} );
You also have i% and %1 which is for integers, and you want strings (%s).
With only one test, you do not need the beforeEach() and can simply do:
const a:string = 'hello';
test.each([[a, 'hello']])(
'.compare(%s, %s)',
(myVariable, expected) => {
expect(myVariable).toBe(expected);
},
);
However, I cannot get this to work either. I can reference the variable directly in the test, such as:
const a:string = 'hello';
test.each([[a, 'hello']])(
'.compare(%s, %s)',
(myVariable, expected) => {
expect(a).toBe(expected);
},
);
Using your myVariable will not get the value from a inside the closed loop of the test. Literals do work though. The beforeEach would defeat the purpose of setting a value there, as it would not need to be changed in the middle of the test.each() since this is meant to run the same test with different data. You can still create objects and other required things in your beforeEach, and reference them directly (my a variable), but the test data that changes for each run does not seem to get the value from the outside loop.