jquery - Triggering JavaScript events in Qunit tests -
i trying test when user clicks in form existing error message go away. reason last test failing , i'm not sure why. i'm new jquery , qunit.
test.html
<!doctype html> <html> <head> <meta charset="utf-8"> <title>javascript tests</title> <link rel="stylesheet" href="qunit.css"> </head> <body> <div id="qunit"></div> <div id="qunit-fixture"> <form> <input name="text" /> <div class="has-error">error text</div> </form> </div> <script src="http://code.jquery.com/jquery.min.js"></script> <script src="qunit.js"></script> <script src="../list.js"></script> <script type="text/javascript"> test("errors should hidden on key press", function() { $('input[name="text"]').trigger('keypress'); equal($('.has-error').is(':visible'), false); }); test("errors not hidden unless there keypress", function() { equal($('.has-error').is(':visible'), true); }); test("errors should hidden on click", function() { $('input[name="text"]').click(); equal($('.has-error').is(':visible'), false); }); </script> </body> </html>
list.js
jquery(document).ready(function ($) { $('input[name="text"]').on('keypress', function() { $('.has-error').hide(); }); $('input[name="text"]').on('click', function() { $('.has-error').hide(); }); })
function setupmodule() { $('input[name="text"]').on('click', function() { $('.has-error').hide(); }) $('input[name="text"]').on('keypress', function() { $('.has-error').hide(); }); } module('tests', {setup:setupmodule}); test("errors should hidden on key press", function() { $('input[name="text"]').trigger('keypress') equal($('.has-error').is(':visible'), false); }); test("errors not hidden unless there keypress", function() { equal($('.has-error').is(':visible'), true); }); test("errors should hidden on click", function() { $('input[name="text"]').click() equal($('.has-error').is(':visible'),false); });
Comments
Post a Comment