I’m just getting started with testing and having a little issue with trying to create dynamic tests.
Here is an example of what I would like to do:
ValidInputs = [“apple”, “orange”, “banana”];
describe(“Test all valid inputs”, function(){
for(key in ValidInputs) {
it(“Will return true for #key”, function() {
expect(ValidInputs).toInclude(key);
});
}
});
That would hopefully generate the following output:
+Test all valid inputs
Will return true for apple (xx ms)
Will return true for orange (xx ms)
Will return true for banana (xx ms)
but it doesn’t work.
I can get this to work but it does not list out the individual items:
describe(“Test all valid inputs”, function(){
beforeEach(function(){ValidInputs = [“apple”, “orange”, “banana”];});
it(“Will return true for all valid inputs”, function() {
for(key in ValidInputs) {
expect(ValidInputs).toInclude(key);
}
});
});
This is a sort of contrived set of code, but I have a requirement to show a test for a set of values that will be given to me (in this case they will be built into components where I may not know the values).
I’m already expecting the “You’re doing it wrong” statement to come from someone, but I would like to know how to do it right with this requirement.
Thanks,
Steve