Skip to content

Commit

Permalink
Merge pull request #1915 from marionettejs/sjs/region-undefined-bug
Browse files Browse the repository at this point in the history
Improve undefined region show message.
  • Loading branch information
jasonLaster committed Sep 25, 2014
2 parents 6f32941 + 307c3c1 commit b1f990a
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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 b1f990a

Please sign in to comment.