Saturday, December 31, 2011

wish I knew Jasmine

I want to learn Jasmine. I sat down to start into it just now and I realize I have a long way to go. I want to set up a simple blob of jQuery and try to get it under test. I wrote some markup in which there is a form field followed by a button followed by another form field in a horizontal row. If one clicks, the button, jQuery moves the copy in the first (left) field to the second (right) field. I'd like to get this under test. I'll work towards as much.

 
 


What is Jasmine? It is a Behavior-driven development testing framework for JavaScript. You may download it at http://pivotal.github.com/jasmine/download.html. Generally, when I speak with others, the consensus seems to be that Jasmine is better than JUnit, which is the other player in this space. So far, I know that when one has a .js file that there should be, as a good convention, a –spec.js file of the same name. The spec file will hold the Jasmine test. I've created myscript.js and now the challenge is on me to create myscript–spec.js

More to come?

 
 

myscript.js:

$(document).ready(function() {

   $("#mover").click(function() {

      var leftvalue = $('#lefty').val();

      $('#righty').val(leftvalue)

   });

});

 
 

myscript.js is called by:

<!DOCTYPE html>

<html lang="en">

   <head>

      <script src="jquery-1.5.js" type="text/javascript"></script>

      <script src="myscript.js" type="text/javascript"></script>

   </head>

   <body>

      <input id="lefty" />

      <button type="button" id="mover">Move Right -></button>

      <input id="righty" />

   </body>

</html>

No comments:

Post a Comment