Jasmine JavaScript Testing - Second Edition

Book description

Test your JavaScript applications efficiently using Jasmine and React.js

In Detail

Take your testing of JavaScript applications to a new level of efficiency and reliability with the help of this book. Starting with the fundamentals of Jasmine and behavior-driven development (BDD), you will learn about tooling and automation. You will learn how to create a sustainable code base with the help of Jasmine. You will also take a look at integrated testing with React.js and Karma, and how you can speed this process up by faking AJAX requests. As you progress through the book, you will learn about the challenges of testing an application built on top of a framework and how you can prevent your application from suffering from dependency management. You will understand the concept of client-side and server-side rendering and test applications using React.js. You will also learn to automate using webpack and work with JavaScript module systems using ECMA Script 6 (ES6) modules.

By the end of this book, you will be a competent web developer with good knowledge and a strong understanding of how to efficiently use the Jasmine framework for testing purposes.

What You Will Learn

  • Understand and use the power of Jasmine to create better and more maintainable code bases

  • Drive your application development entirely by tests

  • Write modular and reusable code through the power of ECMA Script 6 (ES6) modules

  • Use asynchronous tests, stubs, and spies optimally

  • Test drive a React.js single-page application

  • Optimize your code to unleash the power of tooling and automation

  • Table of contents

    1. Jasmine JavaScript Testing Second Edition
      1. Table of Contents
      2. Jasmine JavaScript Testing Second Edition
      3. Credits
      4. About the Author
      5. About the Reviewers
      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. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Getting Started with Jasmine
        1. JavaScript – the bad parts
        2. Jasmine and behavior-driven development
        3. Downloading Jasmine
        4. Summary
      9. 2. Your First Spec
        1. The Investment Tracker application
        2. Jasmine basics and thinking in BDD
        3. Setup and teardown
        4. Nested describes
          1. Setup and teardown
          2. Coding a spec with shared behavior
          3. Understanding matchers
            1. Custom matchers
            2. Built-in matchers
              1. The toEqual built-in matcher
              2. The toBe built-in matcher
              3. The toBeTruthy and toBeFalsy matchers
              4. The toBeUndefined, toBeNull, and toBeNaN built-in matchers
              5. The toBeDefined built-in matcher
              6. The toContain built-in matcher
              7. The toMatch built-in matcher
              8. The toBeLessThan and toBeGreaterThan built-in matchers
              9. The toBeCloseTo built-in matcher
              10. The toThrow built-in matcher
        5. Summary
      10. 3. Testing Frontend Code
        1. Thinking in terms of components (Views)
        2. The module pattern
        3. Using HTML fixtures
        4. Basic View coding rules
          1. The View should encapsulate a DOM element
          2. Integrating Views with observers
        5. Testing Views with jQuery matchers
          1. The toBeMatchedBy jQuery matcher
          2. The toContainHtml jQuery matcher
          3. The toContainElement jQuery matcher
          4. The toHaveValue jQuery matcher
          5. The toHaveAttr jQuery matcher
          6. The toBeFocused jQuery matcher
          7. The toBeDisabled jQuery matcher
          8. More matchers
        6. Summary
      11. 4. Asynchronous Testing – AJAX
        1. Acceptance criterion
        2. Setting up the scenario
          1. Installing Node.js
          2. Coding the server
          3. Running the server
        3. Writing the spec
          1. Asynchronous setups and teardowns
          2. Asynchronous specs
          3. Timeout
        4. Summary
      12. 5. Jasmine Spies
        1. The "bare" spy
        2. Spying on an object's functions
        3. Testing DOM events
        4. Summary
      13. 6. Light Speed Unit Testing
        1. Jasmine stubs
        2. Jasmine Ajax
          1. Installing the plugin
          2. A fake XMLHttpRequest
        3. Summary
      14. 7. Testing React Applications
        1. Project setup
        2. Our first React component
        3. The Virtual DOM
        4. JSX
          1. Using JSX with Jasmine
        5. Component attributes (props)
        6. Component events
        7. Component state
        8. Component life cycle
        9. Composing components
        10. Summary
      15. 8. Build Automation
        1. Module bundler – webpack
          1. Module definition
          2. Webpack project setup
            1. Managing dependencies with NPM
            2. Webpack configuration
          3. The spec runner
          4. Testing a module
        2. Test runner: Karma
        3. Quick feedback loop
          1. Watch and run the tests
          2. Watch and update the browser
        4. Optimizing for production
        5. Static code analysis: JSHint
        6. Continuous integration – Travis-CI
          1. Adding a project to Travis-CI
          2. Project setup
        7. Summary
      16. Index

    Product information

    • Title: Jasmine JavaScript Testing - Second Edition
    • Author(s): Paulo Ragonha
    • Release date: April 2015
    • Publisher(s): Packt Publishing
    • ISBN: 9781785282041