walmartlabs / thorax

Strengthening your Backbone
http://thoraxjs.org/
Other
1.32k stars 129 forks source link

Empty item templates produces holes in collection #408

Open kpdecker opened 9 years ago

kpdecker commented 9 years ago

This can lead to future rendering failures when an inserted item's sibling can not be found.

  it('should work with empty elements', function() {
    var view = new Thorax.View({
      template: Handlebars.compile("{{#collection}}\n{{#if render}}\n{{letter}}\n{{/if}}\n{{/collection}}"),
      collection: new Thorax.Collection([
        {letter: 'a', render: false},
        {letter: 'b', render: true},
        {letter: 'c', render: false},
        {letter: 'd', render: true},
        {letter: 'e', render: true}
      ])
    });
    view.render();
    expect(view.$el.text()).to.equal('bde');
    expect(view.$('[data-model-cid]').length).to.equal(5);
  });
kpdecker commented 9 years ago

Under Handlebars 2.x this will fail with the following failure:

  1) collection should work with empty elements:
     Error: expected 3 to equal 5
      at Assertion.assert (thorax/node_modules/expect.js/index.js:96:13)
      at Assertion.be.Assertion.equal (thorax/node_modules/expect.js/index.js:216:10)
      at Context.<anonymous> (thorax/build/dev/test-fruit-loops-server.js:243:50)
      at Test.Runnable.run (thorax/node_modules/mocha/lib/runnable.js:221:32)
      at Runner.runTest (thorax/node_modules/mocha/lib/runner.js:374:10)
      at thorax/node_modules/mocha/lib/runner.js:452:12
      at next (thorax/node_modules/mocha/lib/runner.js:299:14)
      at thorax/node_modules/mocha/lib/runner.js:309:7
      at next (thorax/node_modules/mocha/lib/runner.js:247:23)
      at Object._onImmediate (thorax/node_modules/mocha/lib/runner.js:276:5)
      at processImmediate [as _immediateCallback] (timers.js:345:15)
kpdecker commented 9 years ago

cf8f48826e6ade9f68b92eef07ce73040e69b790 masks this failure slightly due to the append only mode operation but we should output placeholder elements for empty content items so independent inserts will have the proper placeholders.