You are previewing Backbone.js Testing.
O'Reilly logo
Backbone.js Testing

Book Description

If you dread the business of testing JavaScript and Backbone.js web applications, this book is your guardian angel. In easy stages and lots of examples it takes you through the whole testing situation, introducing you to best practice and current techniques.

  • Create comprehensive test infrastructures

  • Understand and utilize modern frontend testing techniques and libraries

  • Use mocks, spies, and fakes to effortlessly test and observe complex Backbone.js application behavior

  • Automate tests to run from the command line, shell, or practically anywhere

  • In Detail

    Frontend web applications are soaring in popularity and the Backbone.js library is leading this charge with a modular, lightweight approach for organizing JavaScript web applications. At the same time, testing client-side JavaScript and Backbone.js programs remains a difficult and tedious undertaking.

    Backbone.js Testing brings sensible practices and current techniques to the challenges of Backbone.js test development. The book introduces fundamental testing concepts, comprehensive test infrastructure design, and practical exercises to easily and systematically test modern JavaScript web applications.

    The book progresses from Mocha test suites and Chai assertions to advanced test mocks and stubs with Sinon.JS. The requisite libraries and utilities are introduced with in-depth examples and best practices for integration with your applications. The book guides you through the test planning and implementation processes for your application models, views, routers, and other Backbone.js components.

    Backbone.js Testing gives you the tools, examples, and assistance to test your Backbone.js web applications thoroughly, quickly, and with confidence.

    Table of Contents

    1. Backbone.js Testing
      1. Table of Contents
      2. Backbone.js Testing
      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. Who this book is for
        3. Conventions
        4. Reader feedback
        5. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Setting Up a Test Infrastructure
        1. Designing an application and test repository structure
        2. Getting the test libraries
          1. Mocha
          2. Chai
          3. Sinon.JS
        3. Setting up and writing our first tests
          1. The test driver page
          2. Adding some tests
        4. Running and assessing test results
          1. The first test report
          2. Test report actions
          3. Test timing and slow tests
          4. Test failures
        5. Summary
      9. 2. Creating a Backbone.js Application Test Plan
        1. A Backbone.js refresher
        2. Selecting a Backbone.js application to test
          1. Getting acquainted with the Notes application
          2. The anatomy of the Notes application
        3. Test paradigms and methods
        4. Testing concepts, approaches, and planning
        5. Testing individual Backbone.js components
          1. Models
          2. Collections
          3. Templates
          4. Views
          5. Routers
          6. Utilities
        6. Testing application interactions and events
          1. Partial integrations
          2. Events
        7. Dipping our toes in the application testing waters
          1. Namespace
          2. Note model
        8. Running the application tests
        9. Summary
      10. 3. Test Assertions, Specs, and Suites
        1. Choosing a test style that fits
          1. Mocha test interfaces
          2. Chai assertion styles
        2. Trying out some different styles
          1. Mocha and Chai BDD interfaces
          2. Mocha TDD and Chai assert styles
          3. Deciding on the project style
        3. A tour of the Chai assertion library
          1. Chaining objects and assertions
          2. Basic value assertions
          3. Comparing values
          4. Object and array validation
          5. Errors
        4. Getting the application and tests ready to run
          1. The Mocha test runner
          2. Reconfiguring the application for testing
          3. Organizing topics and specifications into test suites
          4. Starting up and winding down tests
        5. Writing Mocha test specifications
          1. Asynchronous behavior in tests
          2. Some Backbone.js collection tests
        6. Testing and supporting Backbone.js views
          1. The Notes application single note view
          2. Creating HTML fixtures for view tests
          3. Walking through the view test suite
        7. Aggregating and running the application tests
        8. Test development tips, tricks, and hints
          1. Isolating and excluding tests
          2. Writing testable application code
        9. Summary
      11. 4. Test Spies
        1. Fake it 'til you make it
        2. Getting to know Sinon.JS
          1. Spying on functions with Sinon.JS
            1. Anonymous spies
            2. Spy assertions
            3. Function spies
            4. Object method spies
          2. Playing in the sandbox with Sinon.JS test helpers
          3. Delving into the Sinon.JS spy API
            1. The spy API
            2. The spy call API
        3. Spicing up Chai with the Sinon.JS plugin
          1. Introducing and installing Chai plugins
          2. The Sinon.JS plugin
        4. Testing Backbone.js components with spies
          1. The Notes menu bar view
            1. The menu bar view
            2. Testing and spying on the menu bar view
          2. The Notes single note view
            1. The single note view
            2. Testing the single note view
          3. Hooking up and running the view tests
        5. Summary
      12. 5. Test Stubs and Mocks
        1. Replacing method behaviors with Sinon.JS stubs
          1. Getting started with stubs
          2. The stub API
        2. Faking and verifying behavior with Sinon.JS mocks
          1. Deciding when to mock
          2. The mock API
        3. Testing Backbone.js components with stubs and mocks
          1. Ensuring stubs and mocks are actually bound
          2. The Notes list item view
            1. The list item view
            2. Testing the list item view
          3. The Notes application router
          4. Running the view and router tests
        4. Finding the rest of the Notes application components
        5. A few more Sinon.JS test helpers
          1. Fake timers
          2. Fake servers
            1. The fake server API
            2. Faking the remote backend in a Backbone.js application
        6. Summary
      13. 6. Automated Web Testing
        1. The world of testing beyond humans and browsers
          1. Continuous integration
          2. Continuous deployment
          3. Other scenarios
        2. Automating browser environments
          1. Remote controlled web browsers
          2. Simulated browser environments
          3. Headless web browsers
          4. Multiple environment aggregators
        3. Headless testing with PhantomJS
          1. Installing PhantomJS and the supporting tools
          2. Running Backbone.js tests with PhantomJS
          3. Automating tests in the code samples
        4. Parting thoughts, next steps, and future ideas
        5. Summary
      14. Index