I'm new to JavaScript. Imagine, I have following piece of code:
$(document).ready(function() {
$('#nights').on('keyup', function() {
var nights = +$(this).val();
var dailyPrice = +$(this).closest(".tour").data("daily-price");
$('#total').text(nights * dailyPrice);
$('#nights-count').text($(this).val());
});
});
How can I unit-test that the anonymous function
- retrieves the value of the current element,
- retrieves the data from
+$(this).closest(".tour").data("daily-price")
and - then calls
text(...)
on$('#total')
and$('#nights-count')
?
Note that I'm interested in unit tests (therefore creating a full-fledged a Selenium test suite, which types in something and then checks the value of the elements isn't suitable for me), which don't require me to add a new abstraction layer.
By abstraction layer I mean this: I could create class JQueryAbstraction
and then 2 sub-classes - one, which calls real jQuery methods and another, which just counts the number of calls.
Aucun commentaire:
Enregistrer un commentaire