I'm writing a test where if the user clicks a button, there should only be 2 scenarios (texts) that could happen.
For example
await t
.click('button')
.expect(Selector('div#result').textContent)
.eql('My text A')
// or 'My text B' ??
How can I test this in TestCafe?
First you await
the user clicks the button, then save the textContent
in a variable, and inside expect
you can check on both conditions with or
operator ||
, if false
it will output the message inside the ok
.
test('Button click results in one of two texts', async t => {
await t.click('button');
const textContent = await Selector('div#result').textContent;
await t.expect(textContent === 'My text A' || textContent === 'My text B')
.ok('Wrong text.');
});