Permalink
Browse files

Changed renderChildInto so it works with elements that are not added …

…to the document yet
  • Loading branch information...
1 parent 95d803e commit 5ff789994d16e4d1520400ed8e70e8ab77fc67af @alexmreis alexmreis committed with jferris Aug 16, 2012
@@ -34,7 +34,7 @@ _.extend(Support.CompositeView.prototype, Backbone.View.prototype, {
renderChildInto: function(view, container) {
this.renderChild(view);
- $(container).empty().append(view.el);
+ this.$(container).empty().append(view.el);
},
appendChild: function(view) {
@@ -42,12 +42,22 @@ describe("Support.CompositeView", function() {
describe("#renderChildInto", function() {
it("renders child into the given element and replaces content there", function() {
$("#test1").text("Replace this!");
+ $("#test").append($("#test1"));
var view = new blankView({el: "#test"});
view.renderChildInto(new orangeView(), "#test1");
- expect($("#test").text()).toEqual("");
expect($("#test1").text()).toEqual("Orange!");
+
+ $("#test1").remove();
+ expect($("#test").text()).toEqual("");
+ });
+
+ it("renders child into a sub-element of the view, even if it is not yet added to the document", function() {
+ var view = new blankView({el: $('<div><div class="inside"></div></div>')});
+ view.renderChildInto(new orangeView(), ".inside");
+
+ expect($(view.el).find('.inside').text()).toEqual("Orange!");
});
});

0 comments on commit 5ff7899

Please sign in to comment.