You are previewing Jasmine Cookbook.
O'Reilly logo
Jasmine Cookbook

Book Description

Over 35 recipes to design and develop Jasmine tests to produce world-class JavaScript applications

In Detail

Jasmine provides a rich set of libraries to design and develop tests for JavaScript applications. Its tests aim to run on any JavaScript-enabled platform and have easy-to-read syntax.

This book is a comprehensive guide to designing and developing Jasmine tests to produce world-class software. The recipes are elaborated using examples from a real-world application, which involves various aspects of designing and developing tests from simple to complex level. You will learn how to create tests for jQuery and Ajax, HTML and JSON fixtures, CoffeeScript, and AngularJS. By learning and applying the best practices throughout this book, you can deliver your applications with zero defects and ensure success for you and your clients.

What You Will Learn

  • Develop JavaScript applications with Jasmine using the behavior-driven development (BDD) process

  • Apply custom matchers by enhancing your Jasmine tests to test specific features or functionality

  • Design Jasmine specs for jQuery and Ajax with HTML and JSON fixtures

  • Generate code coverage analysis for JavaScript code using Karma and Istanbul

  • Create Jasmine tests for CoffeeScript and AngularJS

  • Implement E2E (end-to-end) Jasmine specs for JavaScript applications to simulate a real-time scenario

  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

    Table of Contents

    1. Jasmine Cookbook
      1. Table of Contents
      2. Jasmine Cookbook
      3. Credits
      4. About the Author
      5. About the Reviewer
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Sections
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        5. Conventions
        6. Reader feedback
        7. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Getting Started with Jasmine Framework
        1. Introduction
        2. Writing your first Jasmine test
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        3. Adding specs to your Jasmine test
          1. How to do it…
          2. How it works...
          3. See also
        4. Adding expectations and matchers to the test
          1. How to do it…
          2. How it works...
        5. Applying different matchers to the Jasmine test
          1. How to do it…
          2. How it works...
        6. Applying setup and teardown functions to the Jasmine test
          1. Getting ready
          2. How to do it…
          3. How it works...
        7. Using the "this" keyword
          1. Getting ready
          2. How to do it…
          3. How it works...
      9. 2. Jasmine with TDD and BDD Processes
        1. Introduction
        2. Writing Jasmine tests using TDD and BDD processes
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Creating a Jasmine test for new code using TDD and BDD
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Designing Jasmine tests for existing code using TDD and BDD
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Defining nested suites to write more meaningful specs
          1. Getting ready
          2. How to do it...
          3. How it works...
      10. 3. Customizing Matchers and Jasmine Functions
        1. Introduction
        2. Writing a Jasmine test using a custom equality tester function
          1. How to do it...
          2. How it works...
        3. Writing Jasmine tests with custom matchers
          1. How to do it...
          2. How it works...
        4. Writing Jasmine tests for exceptions
          1. How to do it...
          2. How it works...
        5. Declaring pending specs with Jasmine tests
          1. Getting ready
          2. How to do it...
      11. 4. Designing Specs from Requirement
        1. Introduction
        2. Writing useful specs by analyzing the test requirements
          1. How to do it...
          2. How it works...
        3. Implementing the Jasmine test corresponding to the specs
          1. How to do it...
          2. How it works...
        4. Applying Acceptance Criteria to the Jasmine test
          1. How to do it...
          2. How it works...
        5. Organizing Jasmine specs into groups and subgroups
          1. How to do it...
      12. 5. Jasmine Spies
        1. Introduction
        2. Writing Jasmine tests using the spyOn() method and special matchers for spies
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Writing Jasmine tests using tracking properties
          1. How to do it…
          2. How it works...
        4. Writing Jasmine tests with your own custom spy method
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Using jasmine.any and jasmine.objectContaining
          1. Getting ready
          2. How to do it…
          3. How it works...
        6. Writing Jasmine tests to mock the JavaScript timeout functions
          1. How to do it…
          2. How it works...
      13. 6. Jasmine with AJAX, jQuery, and Fixtures
        1. Introduction
        2. Writing Jasmine specs for AJAX
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Designing Jasmine specs with HTML and JSON fixtures
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Writing Jasmine specs for jQuery
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Writing Jasmine specs using custom jQuery matchers
          1. Getting ready
          2. How to do it…
          3. How it works...
        6. Writing Jasmine specs for asynchronous operations using the done() function
          1. How to do it…
          2. How it works...
      14. 7. Code Coverage with Jasmine Tests
        1. Introduction
        2. Configuring code coverage tools
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        3. Generating code coverage using karma and istanbul
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Writing Jasmine specs for uncovered branches/code
          1. How to do it...
          2. How it works...
        5. Increasing code coverage for existing code
          1. How to do it...
          2. How it works...
      15. 8. Jasmine with Other Tools
        1. Introduction
        2. Writing Jasmine tests for AngularJS
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Using Jasmine with CoffeeScript
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Writing Jasmine tests for Node.js
          1. Getting ready
          2. How to do it...
          3. How it works...
      16. 9. Developing JavaScript Apps Using Jasmine – a Real-time Scenario
        1. Introduction
        2. Defining Jasmine specs corresponding to a user story
          1. Getting ready
          2. How to do it...
          3. See also
        3. Implementing Jasmine specs with Web/HTML
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Implementing Jasmine tests with a Data-Driven approach
          1. How to do it...
        5. Creating Jasmine tests for a change request
          1. Getting ready
          2. How to do it...
      17. Index