Backbone.js Testing

Backbone.js Testing
eBook: $19.99
Formats: PDF, PacktLib, ePub and Mobi formats
save 15%!
Print + free eBook + free PacktLib access to the book: $59.98    Print cover: $39.99
save 33%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Table of Contents
Sample Chapters
  • 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

Book Details

Language : English
Paperback : 168 pages [ 235mm x 191mm ]
Release Date : July 2013
ISBN : 178216524X
ISBN 13 : 9781782165248
Author(s) : Ryan Roemer
Topics and Technologies : All Books, Web Development, Open Source, Web Development

Table of Contents

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

              Ryan Roemer

              Ryan Roemer is the Director of Engineering at Curiosity Media, a language learning startup, where he manages technical operations and leads the development team. He develops (and tests) full-stack JavaScript applications and backend Node.js services. He also works with data mining, cloud architectures, and problems related to large scale distributed systems. He was previously an engineer in the cloud computing storage group of Microsoft's Azure platform and most recently developed the search and cloud architecture for IP Street, a patent data mining startup. Besides engineering, he is a registered patent attorney (inactive), although it has been a long time since he has put on his lawyer hat. You can find him online at and on Twitter at

              Submit Errata

              Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


              - 3 submitted: last submission 25 Feb 2014

              Errata Type: Typo | Page number: 47

              The description of the second bullet point at the beginning of the page should be as follows:

              "after(): This is a setup that occurs once after all tests in a suite are run, with the afterEach() alternative that runs after each test."

              Errata Type: Typo | Page number: 97

              The line "Getting into the application code at notes/app/js/app/views/note-nav.js," should instead read 

              "Getting into the application code at notes/app/js/app/views/note.js,"

              Errata Type: Technical | page number: 13

              The line "Versioned releases—we will use version 1.7.3—are available at either of the following locations:




              should read

              "The version (1.7.3) that we will use is available at: "

              Sample chapters

              You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

              Frequently bought together

              Backbone.js Testing +    Haskell Data Analysis Cookbook =
              50% Off
              the second eBook
              Price for both: £24.35

              Buy both these recommended eBooks together and get 50% off the cheapest eBook.

              What you will learn from this book

              • Install and set up a test infrastructure for Backbone.js applications
              • Run, examine, and understand Mocha test reports
              • Tour the Chai assertion library API with detailed examples
              • Write test suites and specs with the Mocha test framework
              • Fake application behavior in tests using Sinon.JS mocks, spies, and fake servers

              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.


              This book is packed with step-by-step tutorials and instructions in recipe format to help you create test infrastructures and gradually advance your Backbone.js application development and testing skills.

              Who this book is for

              If you are a JavaScript developer looking to create and implement test support for your Backbone.js applications, then this book is ideal for you.

              Code Download and Errata
              Packt Anytime, Anywhere
              Register Books
              Print Upgrades
              eBook Downloads
              Video Support
              Contact Us
              Awards Voting Nominations Previous Winners
              Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
              Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software