I am trying to load files into an array and then run tests on them. This is my code:
let files: string[] = []
describe.only("Name of the group", () => {
beforeAll(() => {
files = ["a", "b"]
})
test.each(files)("runs", f => {
console.log(f)
})
})
However, I get
Error:
.each
called with an empty Array of table data.
What am I doing wrong?
Thanks!
I am trying to load files into an array and then run tests on them. This is my code:
let files: string[] = []
describe.only("Name of the group", () => {
beforeAll(() => {
files = ["a", "b"]
})
test.each(files)("runs", f => {
console.log(f)
})
})
However, I get
Error:
.each
called with an empty Array of table data.
What am I doing wrong?
Thanks!
Share Improve this question edited Feb 12, 2020 at 14:44 Thatkookooguy 7,0221 gold badge33 silver badges59 bronze badges asked Feb 6, 2020 at 11:01 mspoulsenmspoulsen 1,4962 gold badges13 silver badges20 bronze badges1 Answer
Reset to default 7test.each
expects a table value as input. which means an array of arrays. But that is fixed automatically so don't worry about it.
But the call order is important here! Notice that the tests are defined before they are actually run. So, beforeAll
will run after the tests were defined. This means the files
array won't be defined while the tests are being registered.
In order to fix this, you need to make sure the files
array is populated before the tests are read and registered
So something like this:
const files: string[][] = [ ['test1'],['test2'] ];
describe('Something Something', () => {
describe('Name of the group', () => {
test.each(files)('runs %s', (f) => {});
});
});