Skip to content

Commit dec437c

Browse files
committed
Add throw error
1 parent 99c0f7a commit dec437c

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

docs/en/api/options.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ expect(wrapper.find('div')).toBe(true)
6464
#### Passing text
6565

6666
You can pass text to `slots`.
67-
There is a limitation to this.
67+
There is two limitations to this.
68+
69+
This does not support PhantomJS.
6870

6971
The text works below.
7072

src/lib/add-slots.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ function addSlotToVm (vm: Component, slotName: string, slotValue: Component | st
1313
if (!compileToFunctions) {
1414
throwError('vueTemplateCompiler is undefined, you must pass components explicitly if vue-template-compiler is undefined')
1515
}
16+
if (window.navigator.userAgent.match(/PhantomJS/i)) {
17+
throwError('option.slots does not support PhantomJS. Please use Puppeteer')
18+
}
1619
const domParser = new window.DOMParser()
1720
const document = domParser.parseFromString(slotValue, 'text/html')
1821
const _slotValue = slotValue.trim()

test/unit/specs/mount/options/slots.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ import Component from '~resources/components/component.vue'
44
import ComponentWithSlots from '~resources/components/component-with-slots.vue'
55

66
describe('mount.slots', () => {
7+
let _window
8+
9+
beforeEach(() => {
10+
_window = window
11+
})
12+
13+
afterEach(() => {
14+
/* eslint-disable */
15+
window = _window
16+
/* eslint-enable */
17+
})
18+
719
it('mounts component with default slot if passed component in slot object', () => {
820
const wrapper = mount(ComponentWithSlots, { slots: { default: Component }})
921
expect(wrapper.contains(Component)).to.equal(true)
@@ -25,6 +37,15 @@ describe('mount.slots', () => {
2537
expect(wrapper.contains('span')).to.equal(true)
2638
})
2739

40+
it('throws error if the UserAgent is PhantomJS when passed string is in slot object', () => {
41+
/* eslint-disable */
42+
window = { navigator: { userAgent:'PhantomJS' } }
43+
/* eslint-enable */
44+
const message = '[vue-test-utils]: option.slots does not support PhantomJS. Please use Puppeteer'
45+
const fn = () => mount(ComponentWithSlots, { slots: { default: 'foo' }})
46+
expect(fn).to.throw().with.property('message', message)
47+
})
48+
2849
it('mounts component with default slot if passed string in slot object', () => {
2950
const wrapper1 = mount(ComponentWithSlots, { slots: { default: 'foo<span>123</span>{{ foo }}' }})
3051
expect(wrapper1.find('main').html()).to.equal('<main>foo<span>123</span>bar</main>')

0 commit comments

Comments
 (0)