I am looking into starting some client-side testing, but I can’t seem to think of how to properly use qunit. ALl of the documentation examples have unit tests such as
ok( 1 == "1", "Passed!" );
Do we reference HTML in our project or re-write sections of the HTML mimicking it?
Do re reference real Javascript functions or do we rewrite similar functions?
Thanks in advance
I have typically used it to test any client side JavaScript written for a project. Some of the JavaScript may have have public methods that make it easy to test directly. This should be easy to get as a unit.
Typically a lot of JavaScript using jQuery will be event driven. For example, say you have some JavaScript that sends an AJAX call to a server when a user clicks a link with the id of “send-ajax”.
What I would typically do is write out a test that mocks out $.ajax, then creates a link with the ID of “send-ajax”, then simulate a user click, then test that the mocked $.ajax method was called.