Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery testing using jasmine

I am very beginner in jasmine. I dont Know how to test this following jquery code using jasmine.

 if ($('.data-block').length > 0) {
   $('.span4:even', '.data-block').addClass('even');
   $('.span4:odd', '.data-block').addClass('odd');
 }

Can you tell me how i write the testing code using jasmine for about this jquery program. Thank you for your answer.

like image 685
Willing Avatar asked Nov 02 '12 09:11

Willing


1 Answers

You can use Jasmine-JQuery plugin and test against an injected DOM:

https://github.com/velesin/jasmine-jquery

The plugin provides custom matchers such as:

expect($('.span4:even')).toHaveAttr('class', 'even')

Ps Here you have a short introduction.

like image 188
mamoo Avatar answered Oct 23 '22 18:10

mamoo