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