Skip to content

Commit

Permalink
[BUGFIX beta] Fix replace in
Browse files Browse the repository at this point in the history
Resolves #10881
  • Loading branch information
mitchlloyd committed Apr 15, 2015
1 parent ffedc10 commit d9965f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/ember-metal-views/lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ Renderer.prototype.appendAttrTo =
Renderer.prototype.replaceIn =
function Renderer_replaceIn(view, target) {
var morph;
if (target.firstNode) {
morph = this._dom.createMorph(target, target.firstNode, target.lastNode);
if (target.firstChild) {
morph = this._dom.createMorph(target, target.firstChild, target.lastChild);
} else {
morph = this._dom.appendMorph(target);
}
Expand Down
16 changes: 12 additions & 4 deletions packages/ember-views/tests/views/view/replace_in_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,26 @@ QUnit.test("raises an assert when a target does not exist in the DOM", function(


QUnit.test("should remove previous elements when calling replaceIn()", function() {
jQuery("#qunit-fixture").html('<div id="menu"><p>Foo</p></div>');
var viewElem = jQuery('#menu').children();
jQuery("#qunit-fixture").html(`
<div id="menu">
<p id="child"></p>
</div>
`);

view = View.create();

ok(viewElem.length === 1, "should have one element");
var originalChild = jQuery('#child');
ok(originalChild.length === 1, "precond - target starts with child element");

run(function() {
view.replaceIn('#menu');
});

ok(viewElem.length === 1, "should have one element");
originalChild = jQuery('#child');
ok(originalChild.length === 0, "target's original child was removed");

var newChild = jQuery('#menu').children();
ok(newChild.length === 1, "target has new child element");

});

Expand Down

0 comments on commit d9965f6

Please sign in to comment.