@@ -759,22 +759,19 @@ QUnit.test('can specify `@identity` to represent mixed object and primitive item
759
759
equal ( view . $ ( ) . text ( ) , 'foobarbaz' ) ;
760
760
} ) ;
761
761
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 ( ) {
763
763
runDestroy ( view ) ;
764
764
view = EmberView . create ( {
765
765
items : [ 'a' , 'a' , 'a' ] ,
766
766
template : compile ( '{{#each view.items as |item|}}{{item}}{{/each}}' )
767
767
} ) ;
768
768
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' ) ;
775
772
} ) ;
776
773
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 ( ) {
778
775
runDestroy ( view ) ;
779
776
view = EmberView . create ( {
780
777
items : A ( [ 'a' , 'b' , 'c' ] ) ,
@@ -783,12 +780,49 @@ QUnit.test('pushing a new duplicate key will trigger a useful error (temporary u
783
780
784
781
runAppend ( view ) ;
785
782
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' ) ;
794
828
} ) ;
0 commit comments