Testing Views

In notebook:
FrontEndMasters BackboneJS
Created at:
2016-06-11
Updated:
2016-06-11
Tags:
libraries JavaScript testing
creates comment-view-spec.js file. AMD module wrapper added. 
Also includes this file in test/app/main.js, in the AMD dependency list (​define(..,[‘test/views/comment-view-spec.js’])​ 
  var assert = chai.assert;
var CommentView = require('views/comment-view');

describe('ComnentView', function(){
  // first make sure we set up everything correctly
  it('it exists', function(){
    assert.ok(CommentView);
  });
  
  // test that we created the view with a model property (should throw an error if not)
  describe('.initialize', function(){
    it('should throw an error if not passed a model', function(){
      assert.throws(function(){
        new CommentView()
        // second argument is a regex
      }, /must provide a Comment model/);
    })
  });
  
});