Book Image

Jasmine Cookbook

By : Munish Kumar
Book Image

Jasmine Cookbook

By: Munish Kumar

Overview of this book

Table of Contents (16 chapters)
Jasmine Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Writing Jasmine specs for jQuery


In the first recipe, we looked at how to write Jasmine specs for AJAX calls using the jasmine-ajax plugin. In this recipe, you will learn how to write tests for jQuery and DOM manipulation in Jasmine specs.

Getting ready

To understand how to write Jasmine specs with jQuery, let's create the myfixture.html file and consider the following code:

<!DOCTYPE html>
<html>
<body>
<div id="my-fixture">something</div>
</body>
</html>

Here, we simply created HTML file with a div tag and defined id as my-fixture.

Next, let's create the jQuery_example.js file and consider the following code:

function sendRequestWithJQuery(myCallback,showErrorMessage,configurationData) {
  $.ajax({
        url: configurationData.url,
        dataType: "json",
        success: function(responseResult) {
          myCallback(responseResult);
        },
        error:showErrorMessage,
        timeout: configurationData.remainingTime
  });
}
function myCallback...