@@ -632,64 +632,116 @@ describe('Component scoped slot', () => {
632
632
} ) . then ( done )
633
633
} )
634
634
635
- // new in 2.6
636
- describe ( 'slot-props syntax' , ( ) => {
637
- const Foo = {
638
- render ( h ) {
639
- return h ( 'div' , [
640
- this . $scopedSlots . default && this . $scopedSlots . default ( 'from foo default' ) ,
641
- this . $scopedSlots . one && this . $scopedSlots . one ( 'from foo one' ) ,
642
- this . $scopedSlots . two && this . $scopedSlots . two ( 'from foo two' )
643
- ] )
635
+ // 2.6 new slot syntax
636
+ if ( process . env . NEW_SLOT_SYNTAX ) {
637
+ describe ( 'slot-props syntax' , ( ) => {
638
+ const Foo = {
639
+ render ( h ) {
640
+ return h ( 'div' , [
641
+ this . $scopedSlots . default && this . $scopedSlots . default ( 'from foo default' ) ,
642
+ this . $scopedSlots . one && this . $scopedSlots . one ( 'from foo one' ) ,
643
+ this . $scopedSlots . two && this . $scopedSlots . two ( 'from foo two' )
644
+ ] )
645
+ }
644
646
}
645
- }
646
647
647
- const Bar = {
648
- render ( h ) {
649
- return this . $scopedSlots . default && this . $scopedSlots . default ( 'from bar' ) [ 0 ]
648
+ const Bar = {
649
+ render ( h ) {
650
+ return this . $scopedSlots . default && this . $scopedSlots . default ( 'from bar' )
651
+ }
650
652
}
651
- }
652
653
653
- const Baz = {
654
- render ( h ) {
655
- return this . $scopedSlots . default && this . $scopedSlots . default ( 'from baz' ) [ 0 ]
654
+ const Baz = {
655
+ render ( h ) {
656
+ return this . $scopedSlots . default && this . $scopedSlots . default ( 'from baz' )
657
+ }
656
658
}
657
- }
658
659
659
- function runSuite ( syntax ) {
660
- it ( 'default slot' , ( ) => {
661
- const vm = new Vue ( {
662
- template : `<foo ${ syntax } ="foo">{{ foo }}<div>{{ foo }}</div></foo>` ,
663
- components : { Foo }
664
- } ) . $mount ( )
665
- expect ( vm . $el . innerHTML ) . toBe ( `from foo default<div>from foo default</div>` )
666
- } )
660
+ function runSuite ( syntax ) {
661
+ it ( 'default slot' , ( ) => {
662
+ const vm = new Vue ( {
663
+ template : `<foo ${ syntax } ="foo">{{ foo }}<div>{{ foo }}</div></foo>` ,
664
+ components : { Foo }
665
+ } ) . $mount ( )
666
+ expect ( vm . $el . innerHTML ) . toBe ( `from foo default<div>from foo default</div>` )
667
+ } )
667
668
668
- it ( 'nested default slots' , ( ) => {
669
- const vm = new Vue ( {
670
- template : `
671
- <foo ${ syntax } ="foo">
672
- <bar ${ syntax } ="bar">
673
- <baz ${ syntax } ="baz">
674
- {{ foo }} | {{ bar }} | {{ baz }}
675
- </baz>
676
- </bar>
677
- </foo>
678
- ` ,
679
- components : { Foo, Bar, Baz }
680
- } ) . $mount ( )
681
- expect ( vm . $el . innerHTML . trim ( ) ) . toBe ( `from foo default | from bar | from baz` )
682
- } )
669
+ it ( 'nested default slots' , ( ) => {
670
+ const vm = new Vue ( {
671
+ template : `
672
+ <foo ${ syntax } ="foo">
673
+ <bar ${ syntax } ="bar">
674
+ <baz ${ syntax } ="baz">
675
+ {{ foo }} | {{ bar }} | {{ baz }}
676
+ </baz>
677
+ </bar>
678
+ </foo>
679
+ ` ,
680
+ components : { Foo, Bar, Baz }
681
+ } ) . $mount ( )
682
+ expect ( vm . $el . innerHTML . trim ( ) ) . toBe ( `from foo default | from bar | from baz` )
683
+ } )
684
+
685
+ it ( 'default + named slots' , ( ) => {
686
+ const vm = new Vue ( {
687
+ template : `
688
+ <foo ()="foo">
689
+ {{ foo }}
690
+ <template slot="one" ${ syntax } ="one">
691
+ {{ one }}
692
+ </template>
693
+ <template slot="two" ${ syntax } ="two">
694
+ {{ two }}
695
+ </template>
696
+ </foo>
697
+ ` ,
698
+ components : { Foo }
699
+ } ) . $mount ( )
700
+ expect ( vm . $el . innerHTML . replace ( / \s + / g, ' ' ) ) . toMatch ( `from foo default from foo one from foo two` )
701
+ } )
702
+
703
+ it ( 'nested + named + default slots' , ( ) => {
704
+ const vm = new Vue ( {
705
+ template : `
706
+ <foo>
707
+ <template slot="one" ${ syntax } ="one">
708
+ <bar ${ syntax } ="bar">
709
+ {{ one }} {{ bar }}
710
+ </bar>
711
+ </template>
712
+ <template slot="two" ${ syntax } ="two">
713
+ <baz ${ syntax } ="baz">
714
+ {{ two }} {{ baz }}
715
+ </baz>
716
+ </template>
717
+ </foo>
718
+ ` ,
719
+ components : { Foo, Bar, Baz }
720
+ } ) . $mount ( )
721
+ expect ( vm . $el . innerHTML . replace ( / \s + / g, ' ' ) ) . toMatch ( `from foo one from bar from foo two from baz` )
722
+ } )
723
+
724
+ it ( 'should warn slot-props usage on non-component elements' , ( ) => {
725
+ const vm = new Vue ( {
726
+ template : `<div ${ syntax } ="foo"/>`
727
+ } ) . $mount ( )
728
+ expect ( `slot-props cannot be used on non-component elements` ) . toHaveBeenWarned ( )
729
+ } )
730
+ }
731
+
732
+ // run tests for both full syntax and shorthand
733
+ runSuite ( 'slot-props' )
734
+ runSuite ( '()' )
683
735
684
- it ( 'default + named slots' , ( ) => {
736
+ it ( 'shorthand named slots' , ( ) => {
685
737
const vm = new Vue ( {
686
738
template : `
687
739
<foo ()="foo">
688
740
{{ foo }}
689
- <template slot=" one" ${ syntax } ="one">
741
+ <template ( one) ="one">
690
742
{{ one }}
691
743
</template>
692
- <template slot=" two" ${ syntax } ="two">
744
+ <template ( two) ="two">
693
745
{{ two }}
694
746
</template>
695
747
</foo>
@@ -699,97 +751,47 @@ describe('Component scoped slot', () => {
699
751
expect ( vm . $el . innerHTML . replace ( / \s + / g, ' ' ) ) . toMatch ( `from foo default from foo one from foo two` )
700
752
} )
701
753
702
- it ( 'nested + named + default slots ' , ( ) => {
754
+ it ( 'shorthand without scope variable ' , ( ) => {
703
755
const vm = new Vue ( {
704
756
template : `
705
757
<foo>
706
- <template slot="one" ${ syntax } ="one">
707
- <bar ${ syntax } ="bar">
708
- {{ one }} {{ bar }}
709
- </bar>
710
- </template>
711
- <template slot="two" ${ syntax } ="two">
712
- <baz ${ syntax } ="baz">
713
- {{ two }} {{ baz }}
714
- </baz>
715
- </template>
758
+ <template (one)>one</template>
759
+ <template (two)>two</template>
716
760
</foo>
717
761
` ,
718
- components : { Foo, Bar , Baz }
762
+ components : { Foo }
719
763
} ) . $mount ( )
720
- expect ( vm . $el . innerHTML . replace ( / \s + / g, ' ' ) ) . toMatch ( `from foo one from bar from foo two from baz ` )
764
+ expect ( vm . $el . innerHTML . replace ( / \s + / g, ' ' ) ) . toMatch ( `onetwo ` )
721
765
} )
722
766
723
- it ( 'should warn slot-props usage on non-component elements ' , ( ) => {
767
+ it ( 'shorthand named slots on root ' , ( ) => {
724
768
const vm = new Vue ( {
725
- template : `<div ${ syntax } ="foo"/>`
769
+ template : `
770
+ <foo (one)="one">
771
+ {{ one }}
772
+ </foo>
773
+ ` ,
774
+ components : { Foo }
726
775
} ) . $mount ( )
727
- expect ( `slot-props cannot be used on non-component elements` ) . toHaveBeenWarned ( )
776
+ expect ( vm . $el . innerHTML . replace ( / \s + / g , ' ' ) ) . toMatch ( `from foo one` )
728
777
} )
729
- }
730
-
731
- // run tests for both full syntax and shorthand
732
- runSuite ( 'slot-props' )
733
- runSuite ( '()' )
734
-
735
- it ( 'shorthand named slots' , ( ) => {
736
- const vm = new Vue ( {
737
- template : `
738
- <foo ()="foo">
739
- {{ foo }}
740
- <template (one)="one">
741
- {{ one }}
742
- </template>
743
- <template (two)="two">
744
- {{ two }}
745
- </template>
746
- </foo>
747
- ` ,
748
- components : { Foo }
749
- } ) . $mount ( )
750
- expect ( vm . $el . innerHTML . replace ( / \s + / g, ' ' ) ) . toMatch ( `from foo default from foo one from foo two` )
751
- } )
752
778
753
- it ( 'shorthand without scope variable' , ( ) => {
754
- const vm = new Vue ( {
755
- template : `
756
- <foo>
757
- <template (one)>one</template>
758
- <template (two)>two</template>
759
- </foo>
760
- ` ,
761
- components : { Foo }
762
- } ) . $mount ( )
763
- expect ( vm . $el . innerHTML . replace ( / \s + / g, ' ' ) ) . toMatch ( `onetwo` )
764
- } )
765
-
766
- it ( 'shorthand named slots on root' , ( ) => {
767
- const vm = new Vue ( {
768
- template : `
769
- <foo (one)="one">
770
- {{ one }}
771
- </foo>
772
- ` ,
773
- components : { Foo }
774
- } ) . $mount ( )
775
- expect ( vm . $el . innerHTML . replace ( / \s + / g, ' ' ) ) . toMatch ( `from foo one` )
776
- } )
777
-
778
- it ( 'dynamic shorthand' , ( ) => {
779
- const vm = new Vue ( {
780
- data : {
781
- a : 'one' ,
782
- b : 'two'
783
- } ,
784
- template : `
785
- <foo>
786
- <template :(a)="one">{{ one }} </template>
787
- <template :(b)="two">{{ two }}</template>
788
- </foo>
789
- ` ,
790
- components : { Foo }
791
- } ) . $mount ( )
792
- expect ( vm . $el . innerHTML . replace ( / \s + / g, ' ' ) ) . toMatch ( `from foo one from foo two` )
779
+ it ( 'dynamic shorthand' , ( ) => {
780
+ const vm = new Vue ( {
781
+ data : {
782
+ a : 'one' ,
783
+ b : 'two'
784
+ } ,
785
+ template : `
786
+ <foo>
787
+ <template :(a)="one">{{ one }} </template>
788
+ <template :(b)="two">{{ two }}</template>
789
+ </foo>
790
+ ` ,
791
+ components : { Foo }
792
+ } ) . $mount ( )
793
+ expect ( vm . $el . innerHTML . replace ( / \s + / g, ' ' ) ) . toMatch ( `from foo one from foo two` )
794
+ } )
793
795
} )
794
- } )
796
+ }
795
797
} )
0 commit comments