Skip to content

Commit

Permalink
Improve undefined region show message.
Browse files Browse the repository at this point in the history
Fixes #1913
  • Loading branch information
samccone committed Sep 21, 2014
1 parent 122b59d commit 307c3c1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/region.js
@@ -1,4 +1,4 @@
/* jshint maxcomplexity: 10, maxstatements: 29 */
/* jshint maxcomplexity: 10, maxstatements: 29, maxlen: 120 */

// Region
// ------
Expand Down Expand Up @@ -207,6 +207,13 @@ _.extend(Marionette.Region.prototype, Backbone.Events, {
},

_ensureViewIsIntact: function(view) {
if (!view) {
throw new Marionette.Error({
name: 'ViewNotValid',
message: 'The view passed is undefined and therefore invalid. You must pass a view instance to show.'
});
}

if (view.isDestroyed) {
throw new Marionette.Error({
name: 'ViewDestroyedError',
Expand Down
18 changes: 18 additions & 0 deletions test/unit/region.spec.js
Expand Up @@ -858,4 +858,22 @@ describe('region', function() {
expect(this.region.currentView).to.be.undefined;
});
});

describe('when showing undefined in a region', function() {
beforeEach(function() {
this.setFixtures('<div id="region"></div>');

this.region = new Backbone.Marionette.Region({
el: '#region'
});

this.insertUndefined = function() {
this.region.show(undefined);
}.bind(this);
});

it('should throw an error', function() {
expect(this.insertUndefined).to.throw('The view passed is undefined and therefore invalid. You must pass a view instance to show.');
});
});
});

0 comments on commit 307c3c1

Please sign in to comment.