Liad Livnat
Liad Livnat

Reputation: 7475

How do i check if element exists by id with Jasmine?

How do i use jasmine to simply check if element exist on the page by id?

I went over the matchers, toExist() not seems to solve this issue.

This is what i tried:

1. expect(by.id('my-id')).not.toExist();

2. expect($(document)).not.toContain($(#my-id));

can you help?

Upvotes: 18

Views: 43581

Answers (2)

shlensky
shlensky

Reputation: 1401

Using Protractor v1.x (without angularjs-jasmine-matchers):

expect(element(by.id('my-id')).isPresent()).toBe(true);

Upvotes: 22

runTarm
runTarm

Reputation: 11547

To use the angularjs-jasmine-matchers, you could write the test like this:

expect('#my-id').not.toExist();

Upvotes: 11

Related Questions