Willing
Willing

Reputation: 612

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.

Upvotes: 5

Views: 7418

Answers (1)

mamoo
mamoo

Reputation: 8166

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.

Upvotes: 9

Related Questions