Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 299
Liad Livnat Avatar asked Jul 21 '14 12:07

Liad Livnat


2 Answers

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

expect(element(by.id('my-id')).isPresent()).toBe(true);
like image 169
shlensky Avatar answered Sep 17 '22 14:09

shlensky


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

expect('#my-id').not.toExist();
like image 24
runTarm Avatar answered Sep 20 '22 14:09

runTarm