3

It seems that,

t.expect(Selector("[data-testid='foo']")).ok();

and,

t.expect(Selector("[data-testid='foo']").exists).ok();

result in the same outcome so is .exists necessary?

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
rssfrncs
  • 991
  • 4
  • 19

1 Answers1

10

Selector("[data-testid='foo']") returns a Promise. The t.expect(Selector("[data-testid='foo']")).ok(); assertion will always pass regardless of whether there is an element on the page or not. It happens because a Promise instance will be cast to true.  

t.expect(Selector("[data-testid='foo']").exists).ok(); is the correct assertion. It checks an element on the page using the Smart assertion query mechanism

mlosev
  • 5,130
  • 1
  • 19
  • 31