PageRenderTime 32ms CodeModel.GetById 21ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/spec/javascripts/error.spec.js

https://github.com/jdaudier/backbone.marionette
JavaScript | 151 lines | 130 code | 21 blank | 0 comment | 0 complexity | 2de0030bc9d8675f720bbae81451a78c MD5 | raw file
  1describe('Marionette.Error', function() {
  2  it('should be subclass of native Error', function() {
  3    expect(new Marionette.Error()).to.be.instanceOf(Error);
  4  });
  5
  6  describe('when passed a message', function() {
  7    beforeEach(function() {
  8      this.error = new Marionette.Error('Foo');
  9    });
 10
 11    it('should contain the correct properties', function() {
 12      expect(this.error).to.contain({
 13        name: 'Error',
 14        message: 'Foo'
 15      });
 16    });
 17
 18    it('should output the correct string', function() {
 19      expect(this.error.toString()).to.equal('Error: Foo');
 20    });
 21  });
 22
 23  describe('when passed a message and options', function() {
 24    beforeEach(function() {
 25      this.error = new Marionette.Error('Foo', {
 26        name: 'Bar'
 27      });
 28    });
 29
 30    it('should contain the correct properties', function() {
 31      expect(this.error).to.contain({
 32        name: 'Bar',
 33        message: 'Foo'
 34      });
 35    });
 36
 37    it('should output the correct string', function() {
 38      expect(this.error.toString()).to.equal('Bar: Foo');
 39    });
 40  });
 41
 42  describe('when passed a message and options with a url', function() {
 43    beforeEach(function() {
 44      this.error = new Marionette.Error('Foo', {
 45        name: 'Bar',
 46        url: 'Baz'
 47      });
 48    });
 49
 50    it('should contain the correct properties', function() {
 51      expect(this.error).to.contain({
 52        name: 'Bar',
 53        message: 'Foo',
 54        url: 'http://marionettejs.com/docs/' + Marionette.VERSION + '/Baz'
 55      });
 56    });
 57
 58    it('should output the correct string', function() {
 59      expect(this.error.toString()).to.equal('Bar: Foo See: http://marionettejs.com/docs/' + Marionette.VERSION + '/Baz');
 60    });
 61  });
 62
 63  describe('when passed options', function() {
 64    beforeEach(function() {
 65      this.error = new Marionette.Error({
 66        name: 'Foo',
 67        message: 'Bar'
 68      });
 69    });
 70
 71    it('should contain the correct properties', function() {
 72      expect(this.error).to.contain({
 73        name: 'Foo',
 74        message: 'Bar'
 75      });
 76    });
 77
 78    it('should output the correct string', function() {
 79      expect(this.error.toString()).to.equal('Foo: Bar');
 80    });
 81  });
 82
 83  describe('when passed options with a url', function() {
 84    beforeEach(function() {
 85      this.error = new Marionette.Error({
 86        name: 'Foo',
 87        message: 'Bar',
 88        url: 'Baz'
 89      });
 90    });
 91
 92    it('should contain the correct properties', function() {
 93      expect(this.error).to.contain({
 94        name: 'Foo',
 95        message: 'Bar',
 96        url: 'http://marionettejs.com/docs/' + Marionette.VERSION + '/Baz'
 97      });
 98    });
 99
100    it('should output the correct string', function() {
101      expect(this.error.toString()).to.equal('Foo: Bar See: http://marionettejs.com/docs/' + Marionette.VERSION + '/Baz');
102    });
103  });
104
105  describe('when passed valid error properties', function() {
106    beforeEach(function() {
107      this.props = {
108        description  : 'myDescription',
109        fileName     : 'myFileName',
110        lineNumber   : 'myLineNumber',
111        name         : 'myName',
112        message      : 'myMessage',
113        number       : 'myNumber'
114      };
115      this.error = new Marionette.Error(this.props);
116    });
117
118    it('should contain all the valid error properties', function() {
119      expect(this.error).to.contain(this.props);
120    });
121  });
122
123  describe('when passed invalid error properties', function() {
124    beforeEach(function() {
125      this.props = {
126        foo : 'myFoo',
127        bar : 'myBar',
128        baz : 'myBaz'
129      };
130      this.error = new Marionette.Error(this.props);
131    });
132
133    it('should not contain invalid properties', function() {
134      expect(this.error).not.to.contain(this.props);
135    });
136  });
137
138  describe('when extended', function() {
139    beforeEach(function() {
140      this.TypeError = Marionette.Error.extend();
141      this.typeError = new this.TypeError('Foo');
142    });
143
144    it('should subclass the error properly', function() {
145      expect(this.typeError)
146        .to.be.instanceOf(Error)
147        .to.be.instanceOf(Marionette.Error)
148        .to.be.instanceOf(this.TypeError);
149    });
150  });
151});