2

I would like to know how can I check if an element on the UI exists by id or class. I'm using teaspoon-mocha, Sinon, and chai.

I tried next but it doesn't work:

expect($('my-id')).to.be.true;
Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
Jakub
  • 2,367
  • 6
  • 31
  • 82

1 Answers1

5

It would be nice to have slightly more context, but generally speaking with jQuery you should check the length of array returned. And if you use an id the '#' sign must be there. Another thing is that the .true assertion in chai uses a strict === comparison (http://www.chaijs.com/api/bdd/#method_true). So, either

expect($('#my-id').length === 1).to.be.true;

or

expect($('#my-id').length).to.be.ok;
Andrey Stukalin
  • 5,328
  • 2
  • 31
  • 50