Home > Mobile >  How to use logical operator Or in Jasmine?
How to use logical operator Or in Jasmine?

Time:04-23

I need to say the test was successful if one of the two expectations is met: I used the code below, but that's not working

   expect(colorGenerator(testArray ,testMin, testMax)).toEqual("green" || "red")

CodePudding user response:

I think you can do this:

const colors = ['green', 'red'];
const isEitherGreenOrRed = colors.some(color => colorGenerator(testArray ,testMin, testMax) === color);
expect(isEitherGreenOrRed).toBeTrue();

We assign green and red inside of an array and then we check that it is one of the entries with the array some.

CodePudding user response:

You can match with a regex

expect(colorGenerator(testArray ,testMin, testMax)).toMatch(/red|green/)
  • Related