Posts

Showing posts with the label jquery

Mocking Ajax with the JQuery Mockjax Library

Unit testing your JavaScript code to ensure everything works according to plan is a very important and tricky business. Properly testing code bits can save you a lot of time and money. This article focuses not on the general topic of unit testing JavaScript, but more specifically unit testing JQuery Ajax functions. HTML File for the Test. <! DOCTYPE HTML > <html>     <head>         <link rel = "stylesheet" href = "lib/qunit.css" type = "text/css" media = "screen" />         <script src = "lib/qunit.js" ></script>         <script src = "lib/jquery-1.7.js" ></script>         <script src = "lib/json2.js" ></script>         <script src = "lib/jquery.mockjax.js" ></script>      ...

JQuery Timer Library

I have been working on game development for the past month. Building game logic is pretty fun, but the need for a good JavaScript timer was needed. Having done a few searches online, I've found Matt Schmidt JQuery Timer plugin v0.1. Out of the box it does everything I want, but there was one issue that was becoming evident.  JQuery Timer uses JavaScript  setInterval which basically recursively calls the code in the block as shown below          $ . timer ( 1000 , function ( timer ) {                 console . log ( Hello World ! ');             }); In the above block of code, Hello World! is outputted to the console every minute… What if we wanted to display Hello World only once?          $ . timer ( 1000 , function ( timer ...