Skip to content

Commit 3204d4e

Browse files
committed
[BUGFIX release] Test {{each}} with duplicate items.
1 parent 6e3085a commit 3204d4e

File tree

1 file changed

+50
-16
lines changed

1 file changed

+50
-16
lines changed

packages/ember-htmlbars/tests/helpers/each_test.js

+50-16
Original file line numberDiff line numberDiff line change
@@ -759,22 +759,19 @@ QUnit.test('can specify `@identity` to represent mixed object and primitive item
759759
equal(view.$().text(), 'foobarbaz');
760760
});
761761

762-
QUnit.test('duplicate keys trigger a useful error (temporary until we can deal with this properly in HTMLBars)', function() {
762+
QUnit.test('duplicate keys work properly with primitive items', function() {
763763
runDestroy(view);
764764
view = EmberView.create({
765765
items: ['a', 'a', 'a'],
766766
template: compile('{{#each view.items as |item|}}{{item}}{{/each}}')
767767
});
768768

769-
throws(
770-
function() {
771-
runAppend(view);
772-
},
773-
`Duplicate key found ('a') for '{{each}}' helper, please use a unique key or switch to '{{#each model key="@index"}}{{/each}}'.`
774-
);
769+
runAppend(view);
770+
771+
equal(view.$().text(), 'aaa');
775772
});
776773

777-
QUnit.test('pushing a new duplicate key will trigger a useful error (temporary until we can deal with this properly in HTMLBars)', function() {
774+
QUnit.test('pushing a new duplicate key will render properly with primitive items', function() {
778775
runDestroy(view);
779776
view = EmberView.create({
780777
items: A(['a', 'b', 'c']),
@@ -783,12 +780,49 @@ QUnit.test('pushing a new duplicate key will trigger a useful error (temporary u
783780

784781
runAppend(view);
785782

786-
throws(
787-
function() {
788-
run(function() {
789-
view.get('items').pushObject('a');
790-
});
791-
},
792-
`Duplicate key found ('a') for '{{each}}' helper, please use a unique key or switch to '{{#each model key="@index"}}{{/each}}'.`
793-
);
783+
run(function() {
784+
view.get('items').pushObject('a');
785+
});
786+
787+
equal(view.$().text(), 'abca');
788+
});
789+
790+
QUnit.test('duplicate keys work properly with objects', function() {
791+
runDestroy(view);
792+
let duplicateItem = { display: 'foo' };
793+
view = EmberView.create({
794+
items: [
795+
duplicateItem,
796+
duplicateItem,
797+
{ display: 'bar' },
798+
{ display: 'qux' }
799+
],
800+
template: compile('{{#each view.items as |item|}}{{item.display}}{{/each}}')
801+
});
802+
803+
runAppend(view);
804+
805+
equal(view.$().text(), 'foofoobarqux');
806+
});
807+
808+
QUnit.test('pushing a new duplicate key will render properly with objects', function() {
809+
runDestroy(view);
810+
811+
let duplicateItem = { display: 'foo' };
812+
view = EmberView.create({
813+
items: A([
814+
duplicateItem,
815+
{ display: 'bar' },
816+
{ display: 'qux' }
817+
]),
818+
template: compile('{{#each view.items as |item|}}{{item.display}}{{/each}}')
819+
});
820+
821+
runAppend(view);
822+
823+
run(function() {
824+
view.get('items').pushObject(duplicateItem);
825+
});
826+
827+
equal(view.$().text(), 'foobarquxfoo');
794828
});

0 commit comments

Comments
 (0)