@@ -2,9 +2,20 @@ import { compileToFunctions } from 'vue-template-compiler'
22import { mount } from '~vue-test-utils'
33import Component from '~resources/components/component.vue'
44import ComponentWithSlots from '~resources/components/component-with-slots.vue'
5- import { vueVersion } from '~resources/test-utils'
65
76describe ( 'mount.slots' , ( ) => {
7+ let _window
8+
9+ beforeEach ( ( ) => {
10+ _window = window
11+ } )
12+
13+ afterEach ( ( ) => {
14+ if ( ! window . navigator . userAgent . match ( / C h r o m e / i) ) {
15+ window = _window // eslint-disable-line no-native-reassign
16+ }
17+ } )
18+
819 it ( 'mounts component with default slot if passed component in slot object' , ( ) => {
920 const wrapper = mount ( ComponentWithSlots , { slots : { default : Component } } )
1021 expect ( wrapper . contains ( Component ) ) . to . equal ( true )
@@ -26,15 +37,33 @@ describe('mount.slots', () => {
2637 expect ( wrapper . contains ( 'span' ) ) . to . equal ( true )
2738 } )
2839
29- it ( 'mounts component with default slot if passed string in slot object' , ( ) => {
30- if ( vueVersion >= 2.2 ) {
31- const wrapper = mount ( ComponentWithSlots , { slots : { default : 'foo' } } )
32- expect ( wrapper . find ( 'main' ) . text ( ) ) . to . equal ( 'foo' )
33- } else {
34- const message = '[vue-test-utils]: vue-test-utils support for passing text to slots at [email protected] +' 35- const fn = ( ) => mount ( ComponentWithSlots , { slots : { default : 'foo' } } )
36- expect ( fn ) . to . throw ( ) . with . property ( 'message' , message )
40+ it ( 'throws error if the UserAgent is PhantomJS when passed string is in slot object' , ( ) => {
41+ if ( window . navigator . userAgent . match ( / C h r o m e / i) ) {
42+ return
3743 }
44+ window = { navigator : { userAgent : 'PhantomJS' } } // eslint-disable-line no-native-reassign
45+ const message = '[vue-test-utils]: option.slots does not support strings in PhantomJS. Please use Puppeteer, or pass a component'
46+ const fn = ( ) => mount ( ComponentWithSlots , { slots : { default : 'foo' } } )
47+ expect ( fn ) . to . throw ( ) . with . property ( 'message' , message )
48+ } )
49+
50+ it ( 'mounts component with default slot if passed string in slot object' , ( ) => {
51+ const wrapper1 = mount ( ComponentWithSlots , { slots : { default : 'foo<span>123</span>{{ foo }}' } } )
52+ expect ( wrapper1 . find ( 'main' ) . html ( ) ) . to . equal ( '<main>foo<span>123</span>bar</main>' )
53+ const wrapper2 = mount ( ComponentWithSlots , { slots : { default : '<p>1</p>{{ foo }}2' } } )
54+ expect ( wrapper2 . find ( 'main' ) . html ( ) ) . to . equal ( '<main><p>1</p>bar2</main>' )
55+ const wrapper3 = mount ( ComponentWithSlots , { slots : { default : '<p>1</p>{{ foo }}<p>2</p>' } } )
56+ expect ( wrapper3 . find ( 'main' ) . html ( ) ) . to . equal ( '<main><p>1</p>bar<p>2</p></main>' )
57+ const wrapper4 = mount ( ComponentWithSlots , { slots : { default : '123' } } )
58+ expect ( wrapper4 . find ( 'main' ) . html ( ) ) . to . equal ( '<main>123</main>' )
59+ const wrapper5 = mount ( ComponentWithSlots , { slots : { default : '1{{ foo }}2' } } )
60+ expect ( wrapper5 . find ( 'main' ) . html ( ) ) . to . equal ( '<main>1bar2</main>' )
61+ wrapper5 . trigger ( 'keydown' )
62+ expect ( wrapper5 . find ( 'main' ) . html ( ) ) . to . equal ( '<main>1BAR2</main>' )
63+ const wrapper6 = mount ( ComponentWithSlots , { slots : { default : '<p>1</p><p>2</p>' } } )
64+ expect ( wrapper6 . find ( 'main' ) . html ( ) ) . to . equal ( '<main><p>1</p><p>2</p></main>' )
65+ const wrapper7 = mount ( ComponentWithSlots , { slots : { default : '1<p>2</p>3' } } )
66+ expect ( wrapper7 . find ( 'main' ) . html ( ) ) . to . equal ( '<main>1<p>2</p>3</main>' )
3867 } )
3968
4069 it ( 'throws error if passed string in default slot object and vue-template-compiler is undefined' , ( ) => {
@@ -59,14 +88,8 @@ describe('mount.slots', () => {
5988 } )
6089
6190 it ( 'mounts component with default slot if passed string in slot text array object' , ( ) => {
62- if ( vueVersion >= 2.2 ) {
63- const wrapper = mount ( ComponentWithSlots , { slots : { default : [ 'foo' , 'bar' ] } } )
64- expect ( wrapper . find ( 'main' ) . text ( ) ) . to . equal ( 'foobar' )
65- } else {
66- const message = '[vue-test-utils]: vue-test-utils support for passing text to slots at [email protected] +' 67- const fn = ( ) => mount ( ComponentWithSlots , { slots : { default : [ 'foo' , 'bar' ] } } )
68- expect ( fn ) . to . throw ( ) . with . property ( 'message' , message )
69- }
91+ const wrapper = mount ( ComponentWithSlots , { slots : { default : [ '{{ foo }}<span>1</span>' , 'bar' ] } } )
92+ expect ( wrapper . find ( 'main' ) . html ( ) ) . to . equal ( '<main>bar<span>1</span>bar</main>' )
7093 } )
7194
7295 it ( 'throws error if passed string in default slot array vue-template-compiler is undefined' , ( ) => {
0 commit comments