Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jasmine tests check if html contains text and return boolean

expect(view.$el.html()).toContain('Admin'); 

The view does contain the word 'Admin' so I was expecting it to return true. How can I achieve this?

expect(view.$el.html()).toContain('Admin'); 

This returns undefined. How can I make it return true?

<header class="main">   <div id="heading">     <ul class="header-view right">       <li class="inline"><a href="#link" class="button help-btn tab-btn"><span>  </span>Help</a></li>       <li class="inline last"><a href="#og" class="button admin-btn tab-btn expand-admin"><span></span>Admin</a></li>     </ul>   </div> </header> 

This is what is returned from view.$el.html

Please help.

like image 306
Spdexter Avatar asked Mar 31 '15 11:03

Spdexter


People also ask

How do I ignore Jasmine test?

Excluding Tests / Specs If you want to exclude a specific test, simply use xit() instead of it() . The x means exclude. describe('description', function () { xit('description', function () {}); }); If you want to exclude an entire describe block, use xdescribe() instead of describe() .

Does Jasmine run tests in order?

Currently (v2. x) Jasmine runs tests in the order they are defined.


Video Answer


1 Answers

toContain() now can actually be used for substring in string checks:

expect(view.$el.html()).toContain('Admin'); 
like image 198
alecxe Avatar answered Sep 19 '22 17:09

alecxe