Cover image for JavaScript Testing with Jasmine

Book description

Developers looking to keep their JavaScript code bug-free will want to unit test using Jasmine, one of the most popular unit testing frameworks around. Any project of meaningful size should be automatically tested to help catch bugs as early as possible. Jasmine, a testing framework for JavaScript, makes it easy to test JavaScript projects, from browser-based applications to Node.js.

Table of Contents

  1. Special Upgrade Offer
  2. Preface
    1. Who Should Read This Book
    2. Conventions Used in This Book
    3. Using Code Examples
    4. Safari® Books Online
    5. How to Contact Us
    6. Acknowledgments
  3. 1. Intro to Testing
    1. What Is Software Testing?
    2. Why Is It Useful?
    3. Test-Driven Development
    4. Behavior-Driven Development
  4. 2. Jasmine
    1. What Is Jasmine?
    2. Getting Set Up with Jasmine
    3. Testing Existing Code with describe, it, and expect
      1. An Example to Test
      2. Jasmine Time!
    4. Matchers
    5. Writing the Tests First with Test-Driven Development
  5. 3. Writing Good Tests
    1. Cardinal Rule: When in Doubt, Test
    2. Test Components
    3. Black-Box Testing
  6. 4. Matchers in Depth
    1. Equality: toEqual
    2. Identity: toBe
    3. Yes or No? toBeTruthy, toBeFalsy
    4. Negate Other Matchers with not
    5. Check If an Element Is Present with toContain
    6. Is It Defined? toBeDefined, toBeUndefined
    7. Nullness: toBeNull
    8. Is It NaN? toBeNaN
    9. Comparators: toBeGreaterThan, toBeLessThan
    10. Nearness: toBeCloseTo
    11. Using toMatch with Regular Expressions
    12. Checking If a Function Throws an Error with toThrow
    13. Custom Matchers
  7. 5. More Jasmine Features
    1. Before and After
    2. Nested Suites
    3. Skipping Specs and Suites
    4. Matching Class Names
  8. 6. Spies
    1. The Basics: Spying on a Function
    2. Calling Through: Making Your Spy Even Smarter
    3. Making Sure a Spy Returns a Specific Value
    4. Replacing a Function with a Completely Different Spy
    5. Creating a New Spy Function
    6. Creating a New Spy Object
  9. 7. Using Jasmine with Other Tools
    1. Jasmine and CoffeeScript
    2. Jasmine and Node.js
      1. Installing jasmine-node on Unix and Linux
      2. Installing jasmine-node on Windows
      3. Basic Usage
      4. Asynchronous Tests with jasmine-node
      5. jasmine-node and CoffeeScript
    3. Jasmine and Ruby on Rails
      1. Installation
      2. Usage
    4. Jasmine with Non-Rails Ruby
    5. More Tools
  10. 8. Reference
    1. Jasmine on the Web
    2. The Basic Structure of a Suite
    3. Matchers Reference
    4. List of Falsy Values
    5. Reserved Words in Jasmine
  11. About the Author
  12. Colophon
  13. Special Upgrade Offer
  14. Copyright