Skip to content

Commit

Permalink
If region selector is not found within a given context return nothing (
Browse files Browse the repository at this point in the history
…#3425)

Resolves #3424

v3.4.0 introduced a region selector
  • Loading branch information
paulfalgout authored and JSteunou committed Aug 16, 2017
1 parent 1962fbb commit 4af7db8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/region.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ const Region = MarionetteObject.extend({
const context = _.result(this, 'parentEl');

if (context && _.isString(el)) {
const $el = this.Dom.findEl(context, el);
if ($el.length) { return $el; }
return this.Dom.findEl(context, el);
}

return this.Dom.getEl(el);
Expand Down
26 changes: 26 additions & 0 deletions test/unit/common/build-region.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,32 @@ describe('Region', function() {
it('uses the el', function() {
expect(this.region.el).to.equal(this.fooSelector);
});

describe('with `parentEl` also defined including the selector', function() {
beforeEach(function() {
this.setFixtures('<div id="parent"><div id="child">text</div></div>');
this.parentEl = $('#parent');
this.definition = _.defaults({parentEl: this.parentEl, el: '#child' }, this.definition);
this.region = this.view.addRegion(_.uniqueId('region_'),this.definition);
});

it('returns the jQuery(el)', function() {
expect(this.region.getEl(this.region.el).text()).to.equal($(this.region.el).text());
});
});

describe('with `parentEl` also defined excluding the selector', function() {
beforeEach(function() {
this.setFixtures('<div id="parent"></div><div id="not-child">text</div>');
this.parentEl = $('#parent');
this.definition = _.defaults({parentEl: this.parentEl, el: '#not-child' }, this.definition);
this.region = this.view.addRegion(_.uniqueId('region_'),this.definition);
});

it('returns the jQuery(el)', function() {
expect(this.region.getEl(this.region.el).text()).to.not.equal($(this.region.el).text());
});
});
});

describe('when el is an HTML node', function() {
Expand Down

0 comments on commit 4af7db8

Please sign in to comment.