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.
assert( willBeAnAmazingProgrammer(SE.users.resting) ) => true
– Martin Josefsson Nov 18 '13 at 21:23disabled
attribute was added andbtn-blue
class was removed. Its the same principle with what you and @Dan1701 wrote, with the only difference of using a unit testing framework. Both are correct, but I have to chose 1. I choose your's for simplicity's sake. But thanks to both :) – resting Nov 19 '13 at 3:21assert()
s really are glorified==
or===
. So in the end pretty simple when you get it! – Martin Josefsson Nov 19 '13 at 10:07