@@ -14,6 +14,16 @@
diff --git a/test/unit/specs/mount/options/slots.spec.js b/test/unit/specs/mount/options/slots.spec.js
index 73191f2a1..bf4199a87 100644
--- a/test/unit/specs/mount/options/slots.spec.js
+++ b/test/unit/specs/mount/options/slots.spec.js
@@ -2,9 +2,20 @@ import { compileToFunctions } from 'vue-template-compiler'
import { mount } from '~vue-test-utils'
import Component from '~resources/components/component.vue'
import ComponentWithSlots from '~resources/components/component-with-slots.vue'
-import { vueVersion } from '~resources/test-utils'
describe('mount.slots', () => {
+ let _window
+
+ beforeEach(() => {
+ _window = window
+ })
+
+ afterEach(() => {
+ if (!window.navigator.userAgent.match(/Chrome/i)) {
+ window = _window // eslint-disable-line no-native-reassign
+ }
+ })
+
it('mounts component with default slot if passed component in slot object', () => {
const wrapper = mount(ComponentWithSlots, { slots: { default: Component }})
expect(wrapper.contains(Component)).to.equal(true)
@@ -26,15 +37,33 @@ describe('mount.slots', () => {
expect(wrapper.contains('span')).to.equal(true)
})
- it('mounts component with default slot if passed string in slot object', () => {
- if (vueVersion >= 2.2) {
- const wrapper = mount(ComponentWithSlots, { slots: { default: 'foo' }})
- expect(wrapper.find('main').text()).to.equal('foo')
- } else {
- const message = '[vue-test-utils]: vue-test-utils support for passing text to slots at vue@2.2+'
- const fn = () => mount(ComponentWithSlots, { slots: { default: 'foo' }})
- expect(fn).to.throw().with.property('message', message)
+ it('throws error if the UserAgent is PhantomJS when passed string is in slot object', () => {
+ if (window.navigator.userAgent.match(/Chrome/i)) {
+ return
}
+ window = { navigator: { userAgent: 'PhantomJS' }} // eslint-disable-line no-native-reassign
+ const message = '[vue-test-utils]: option.slots does not support strings in PhantomJS. Please use Puppeteer, or pass a component'
+ const fn = () => mount(ComponentWithSlots, { slots: { default: 'foo' }})
+ expect(fn).to.throw().with.property('message', message)
+ })
+
+ it('mounts component with default slot if passed string in slot object', () => {
+ const wrapper1 = mount(ComponentWithSlots, { slots: { default: 'foo
123{{ foo }}' }})
+ expect(wrapper1.find('main').html()).to.equal('
foo123bar')
+ const wrapper2 = mount(ComponentWithSlots, { slots: { default: '
1
{{ foo }}2' }})
+ expect(wrapper2.find('main').html()).to.equal('
1
bar2')
+ const wrapper3 = mount(ComponentWithSlots, { slots: { default: '
1
{{ foo }}
2
' }})
+ expect(wrapper3.find('main').html()).to.equal('
1
bar2
')
+ const wrapper4 = mount(ComponentWithSlots, { slots: { default: '123' }})
+ expect(wrapper4.find('main').html()).to.equal('
123')
+ const wrapper5 = mount(ComponentWithSlots, { slots: { default: '1{{ foo }}2' }})
+ expect(wrapper5.find('main').html()).to.equal('
1bar2')
+ wrapper5.trigger('keydown')
+ expect(wrapper5.find('main').html()).to.equal('
1BAR2')
+ const wrapper6 = mount(ComponentWithSlots, { slots: { default: '
1
2
' }})
+ expect(wrapper6.find('main').html()).to.equal('
1
2
')
+ const wrapper7 = mount(ComponentWithSlots, { slots: { default: '1
2
3' }})
+ expect(wrapper7.find('main').html()).to.equal('
12
3')
})
it('throws error if passed string in default slot object and vue-template-compiler is undefined', () => {
@@ -59,14 +88,8 @@ describe('mount.slots', () => {
})
it('mounts component with default slot if passed string in slot text array object', () => {
- if (vueVersion >= 2.2) {
- const wrapper = mount(ComponentWithSlots, { slots: { default: ['foo', 'bar'] }})
- expect(wrapper.find('main').text()).to.equal('foobar')
- } else {
- const message = '[vue-test-utils]: vue-test-utils support for passing text to slots at vue@2.2+'
- const fn = () => mount(ComponentWithSlots, { slots: { default: ['foo', 'bar'] }})
- expect(fn).to.throw().with.property('message', message)
- }
+ const wrapper = mount(ComponentWithSlots, { slots: { default: ['{{ foo }}
1', 'bar'] }})
+ expect(wrapper.find('main').html()).to.equal('
bar1bar')
})
it('throws error if passed string in default slot array vue-template-compiler is undefined', () => {