O'Reilly logo

Jasmine JavaScript Testing by Paulo Ragonha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Testing Backbone collections

Backbone collections are basically Arrays with superpowers:

  • They come with a bunch of enumerable functions built in, such as map, sort, and select
  • They have support for all sorts of events such as addition, removal, and even changes made to individual models it contains
  • They support reading data from a remote server

Expect to use it a lot in conjunction with models in your Backbone application.

Let's see a small code snippet to get a feeling on how it works. Here we instantiate a new collection passing an array with an initial data item for it to start:

var collection = new Backbone.Collection([
  { id: 1, name 'first' }
]);

It will by default, create a new Backbone.Model for each object in that array, but it is possible to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required