I have made a simplified version of my issue to illustrate, here is the code :
class mock {
constructor(a, b, c) {
this.a = a;
this.b = b;
this.c = c;
}
getFunNames() {
return ["funNameA", "funNameB", "funNameC"];
}
funNameA() {
return this.a;
}
funNameB() {
return this.b;
}
funNameC() {
return this.c;
}
}
var value = new mock(1, 2, 3);
var funnames = value.getFunNames();
var succeeded = 0;
var awaited = 0;
for (let i in funnames) {
awaited += 1;
}
for (let i in funnames) {
test("Empty test for " + funnames[i], () => {
expect(() => {
value[funnames[i]]();
succeeded++;
}).not.toThrowError();
});
}
test("test all tests have passed", () => {
expect(awaited).toBe(succeeded);
});
This is working fine. However, in my real code situation, I have a random fatal failure that happen once in a while, non predictably, right where I create an object of the class that "mock" represent.
So I need to enclose it in a test, in order to keep an eye on whatever log jest could get from this fatal failure.
So basically, I need to set "value" from inside a test, then, prepare tests from this value outside for generating new tests.
I know about this documentation on how to customize test steps jest documentation : Setup and Teardown
but, since I have to get some result from value, in order to prepares the tests, I've not been able to use test.each, which seem to never get access to whatever value I want to add in the variable I give it, since I do it after the code Have been launched. Also, starting when I set "value" from a test, I can not access value content outside others test, I can in any test, but not from outside test.
So, how can I test setting value, then, accede this value outside test to prepare my next tests, and then, do whatever tests I have left? I have tried a lot of thing but nothing has worked so far. I don't know what I am missing.
question from:
https://stackoverflow.com/questions/65644367/trying-to-generate-dynamique-test-each-with-jest 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…