QUnit Unit Testing: Test Mouse Click
Posted
by Ngu Soon Hui
on Stack Overflow
See other posts from Stack Overflow
or by Ngu Soon Hui
Published on 2009-06-16T15:42:57Z
Indexed on
2010/03/09
6:06 UTC
Read the original article
Hit count: 344
I have the following HTML code:
<div id="main">
<form Id="search-form" action="/ViewRecord/AllRecord" method="post">
<div>
<fieldset>
<legend>Search</legend>
<p>
<label for="username">Staff name</label>
<input id="username" name="username" type="text" value="" />
<label for="softype"> software type</label>
<input type="submit" value="Search" />
</p>
</fieldset>
</div>
</form>
</div>
And the following Javascript code ( with JQuery as the library):
$(function() {
$("#username").click(function() {
$.getJSON("ViewRecord/GetSoftwareChoice", {},
function(data) {
// use data to manipulate other controls
});
});
});
Now, how to test $("#username").click
so that for a given input, it
- calls the correct url ( in this case, its
ViewRecord/GetSoftwareChoice
) - And, the output is expected (in this case,
function(data)
) behaves correctly?
Any idea how to do this with QUnit?
Edit: I read the QUnit examples, but they seem to be dealing with a simple scenario with no AJAX interaction. And although there are ASP.NET MVC examples, but I think they are really testing the output of the server to an AJAX call, i.e., it's still testing the server response, not the AJAX response. What I want is how to test the client side response.
© Stack Overflow or respective owner