Advise how to write a simple test for this javascript snippet?

Posted by resting on Programmers See other posts from Programmers or by resting
Published on 2013-08-26T09:30:46Z Indexed on 2013/11/11 4:12 UTC
Read the original article Hit count: 122

Filed under:
|

I'm trying to start unit testing (not using any testing frameworks) for my javascripts.

Here's one example of it.

var obj = {};

obj.disableBtn = function ($btn, style) {
  $btn.attr('disabled','disabled').addClass('disabled').removeClass(style);
};

The use case is as such:

obj.disableBtn($('.submit'), 'btn-blue');

What it does is simply add the disabled attribute, add the disabled class, and remove the btn-blue style.

Please advise how would a typical test case look like in this case.

I have a little knowledge on testing using assert(), but have no idea how to go about it when it involves verifying the result on HTML elements.

© Programmers or respective owner

Related posts about JavaScript

Related posts about unit-testing