Skip to content

Commit e9f3305

Browse files
38elementseddyerburgh
authored andcommitted
fix: remove phantomjs limitation (#663)
1 parent b15fc5f commit e9f3305

File tree

4 files changed

+33
-89
lines changed

4 files changed

+33
-89
lines changed

Diff for: docs/api/options.md

-8
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,6 @@ const wrapper = shallowMount(Component, {
5959
expect(wrapper.find('div')).toBe(true)
6060
```
6161

62-
### Passing text
63-
64-
You can pass text to `slots`.
65-
There is a limitation to this.
66-
67-
This does not support PhantomJS.
68-
You can use [Puppeteer](https://github.com/karma-runner/karma-chrome-launcher#headless-chromium-with-puppeteer) as an alternative.
69-
7062
## scopedSlots
7163

7264
- type: `{ [name: string]: string }`

Diff for: docs/ja/api/options.md

-6
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ const wrapper = shallowMount(Component, {
5454
expect(wrapper.find('div')).toBe(true)
5555
```
5656

57-
## テキストを渡す
58-
59-
テキストを値として `slots` に渡すことはできますが、1つ制限事項があります。
60-
PhantomJS をサポートしません。
61-
代わりに [Puppeteer](https://github.com/karma-runner/karma-chrome-launcher#headless-chromium-with-puppeteer) を使用してください。
62-
6357
## scopedSlots
6458

6559
- 型: `{ [name: string]: string }`

Diff for: packages/create-instance/add-slots.js

-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ function validateEnvironment (): void {
2121
if (typeof window === 'undefined') {
2222
throwError('the slots string option does not support strings in server-test-uitls.')
2323
}
24-
if (window.navigator.userAgent.match(/PhantomJS/i)) {
25-
throwError('the slots option does not support strings in PhantomJS. Please use Puppeteer, or pass a component.')
26-
}
2724
}
2825

2926
function addSlotToVm (vm: Component, slotName: string, slotValue: SlotValue): void {

Diff for: test/specs/mounting-options/slots.spec.js

+33-72
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,14 @@ import ComponentWithSlots from '~resources/components/component-with-slots.vue'
44
import ComponentAsAClass from '~resources/components/component-as-a-class.vue'
55
import {
66
describeWithMountingMethods,
7-
vueVersion,
8-
isRunningPhantomJS
7+
vueVersion
98
} from '~resources/utils'
109
import {
1110
itSkipIf,
1211
itDoNotRunIf
1312
} from 'conditional-specs'
1413

1514
describeWithMountingMethods('options.slots', (mountingMethod) => {
16-
let _window
17-
18-
beforeEach(() => {
19-
if (typeof window !== 'undefined') {
20-
_window = window
21-
}
22-
})
23-
24-
afterEach(() => {
25-
if (typeof window !== 'undefined' && !window.navigator.userAgent.match(/Chrome/i)) {
26-
window = _window // eslint-disable-line no-native-reassign
27-
}
28-
})
29-
3015
it('mounts component with default slot if passed component in slot object', () => {
3116
const wrapper = mountingMethod(ComponentWithSlots, { slots: { default: Component }})
3217
if (mountingMethod.name === 'renderToString') {
@@ -38,7 +23,6 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
3823

3924
itDoNotRunIf(
4025
mountingMethod.name === 'shallowMount' ||
41-
isRunningPhantomJS ||
4226
process.env.TEST_ENV === 'node',
4327
'mounts component with default slot if passed component as string in slot object', () => {
4428
const CustomComponent = {
@@ -85,7 +69,7 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
8569
})
8670

8771
itDoNotRunIf(
88-
process.env.TEST_ENV === 'node' || isRunningPhantomJS,
72+
process.env.TEST_ENV === 'node',
8973
'mounts component with default slot if passed string in slot object', () => {
9074
const wrapper = mountingMethod(ComponentWithSlots, { slots: { default: '<span />' }})
9175
if (mountingMethod.name === 'renderToString') {
@@ -96,7 +80,7 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
9680
})
9781

9882
itDoNotRunIf(
99-
process.env.TEST_ENV === 'node' || vueVersion < 2.3 || isRunningPhantomJS,
83+
process.env.TEST_ENV === 'node' || vueVersion < 2.3,
10084
'works correctly with class component', () => {
10185
const wrapper = mountingMethod(ComponentAsAClass, { slots: { default: '<span />' }})
10286
if (mountingMethod.name === 'renderToString') {
@@ -106,27 +90,6 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
10690
}
10791
})
10892

109-
itDoNotRunIf(
110-
typeof window === 'undefined' || window.navigator.userAgent.match(/Chrome/i),
111-
'works if the UserAgent is PhantomJS when passed Component is in slot object', () => {
112-
window = { navigator: { userAgent: 'PhantomJS' }} // eslint-disable-line no-native-reassign
113-
const wrapper = mountingMethod(ComponentWithSlots, { slots: { default: [Component] }})
114-
if (mountingMethod.name === 'renderToString') {
115-
expect(wrapper).contains('<div></div>')
116-
} else {
117-
expect(wrapper.contains(Component)).to.equal(true)
118-
}
119-
})
120-
121-
itDoNotRunIf(
122-
typeof window === 'undefined' || window.navigator.userAgent.match(/Chrome/i),
123-
'throws error if the UserAgent is PhantomJS when passed string is in slot object', () => {
124-
window = { navigator: { userAgent: 'PhantomJS' }} // eslint-disable-line no-native-reassign
125-
const message = '[vue-test-utils]: the slots option does not support strings in PhantomJS. Please use Puppeteer, or pass a component.'
126-
const fn = () => mountingMethod(ComponentWithSlots, { slots: { default: 'foo' }})
127-
expect(fn).to.throw().with.property('message', message)
128-
})
129-
13093
itDoNotRunIf(
13194
process.env.TEST_ENV !== 'node',
13295
'throws error passed string is in slot object', () => {
@@ -135,30 +98,28 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
13598
expect(fn).to.throw().with.property('message', message)
13699
})
137100

138-
itDoNotRunIf(
139-
isRunningPhantomJS,
140-
'mounts component with default slot if passed string in slot object', () => {
141-
if (mountingMethod.name === 'renderToString') {
142-
return
143-
}
144-
const wrapper1 = mountingMethod(ComponentWithSlots, { slots: { default: 'foo<span>123</span>{{ foo }}' }})
145-
expect(wrapper1.find('main').html()).to.equal('<main>foo<span>123</span>bar</main>')
146-
const wrapper2 = mountingMethod(ComponentWithSlots, { slots: { default: '<p>1</p>{{ foo }}2' }})
147-
expect(wrapper2.find('main').html()).to.equal('<main><p>1</p>bar2</main>')
148-
const wrapper3 = mountingMethod(ComponentWithSlots, { slots: { default: '<p>1</p>{{ foo }}<p>2</p>' }})
149-
expect(wrapper3.find('main').html()).to.equal('<main><p>1</p>bar<p>2</p></main>')
150-
const wrapper4 = mountingMethod(ComponentWithSlots, { slots: { default: '123' }})
151-
expect(wrapper4.find('main').html()).to.equal('<main>123</main>')
152-
const wrapper5 = mountingMethod(ComponentWithSlots, { slots: { default: '1{{ foo }}2' }})
153-
expect(wrapper5.find('main').html()).to.equal('<main>1bar2</main>')
154-
wrapper5.trigger('keydown')
155-
const wrapper6 = mountingMethod(ComponentWithSlots, { slots: { default: '<p>1</p><p>2</p>' }})
156-
expect(wrapper6.find('main').html()).to.equal('<main><p>1</p><p>2</p></main>')
157-
const wrapper7 = mountingMethod(ComponentWithSlots, { slots: { default: '1<p>2</p>3' }})
158-
expect(wrapper7.find('main').html()).to.equal('<main>1<p>2</p>3</main>')
159-
const wrapper8 = mountingMethod(ComponentWithSlots, { slots: { default: ' space ' }})
160-
expect(wrapper8.find('main').html()).to.equal('<main> space </main>')
161-
})
101+
it('mounts component with default slot if passed string in slot object', () => {
102+
if (mountingMethod.name === 'renderToString') {
103+
return
104+
}
105+
const wrapper1 = mountingMethod(ComponentWithSlots, { slots: { default: 'foo<span>123</span>{{ foo }}' }})
106+
expect(wrapper1.find('main').html()).to.equal('<main>foo<span>123</span>bar</main>')
107+
const wrapper2 = mountingMethod(ComponentWithSlots, { slots: { default: '<p>1</p>{{ foo }}2' }})
108+
expect(wrapper2.find('main').html()).to.equal('<main><p>1</p>bar2</main>')
109+
const wrapper3 = mountingMethod(ComponentWithSlots, { slots: { default: '<p>1</p>{{ foo }}<p>2</p>' }})
110+
expect(wrapper3.find('main').html()).to.equal('<main><p>1</p>bar<p>2</p></main>')
111+
const wrapper4 = mountingMethod(ComponentWithSlots, { slots: { default: '123' }})
112+
expect(wrapper4.find('main').html()).to.equal('<main>123</main>')
113+
const wrapper5 = mountingMethod(ComponentWithSlots, { slots: { default: '1{{ foo }}2' }})
114+
expect(wrapper5.find('main').html()).to.equal('<main>1bar2</main>')
115+
wrapper5.trigger('keydown')
116+
const wrapper6 = mountingMethod(ComponentWithSlots, { slots: { default: '<p>1</p><p>2</p>' }})
117+
expect(wrapper6.find('main').html()).to.equal('<main><p>1</p><p>2</p></main>')
118+
const wrapper7 = mountingMethod(ComponentWithSlots, { slots: { default: '1<p>2</p>3' }})
119+
expect(wrapper7.find('main').html()).to.equal('<main>1<p>2</p>3</main>')
120+
const wrapper8 = mountingMethod(ComponentWithSlots, { slots: { default: ' space ' }})
121+
expect(wrapper8.find('main').html()).to.equal('<main> space </main>')
122+
})
162123

163124
itSkipIf(mountingMethod.name === 'renderToString',
164125
'throws error if passed string in default slot object and vue-template-compiler is undefined', () => {
@@ -178,7 +139,7 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
178139
})
179140

180141
itDoNotRunIf(
181-
process.env.TEST_ENV === 'node' || isRunningPhantomJS,
142+
process.env.TEST_ENV === 'node',
182143
'mounts component with default slot if passed string in slot array object', () => {
183144
const wrapper = mountingMethod(ComponentWithSlots, { slots: { default: ['<span />'] }})
184145
if (mountingMethod.name === 'renderToString') {
@@ -189,7 +150,7 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
189150
})
190151

191152
itDoNotRunIf(
192-
process.env.TEST_ENV === 'node' || isRunningPhantomJS,
153+
process.env.TEST_ENV === 'node',
193154
'mounts component with default slot if passed string in slot text array object', () => {
194155
const wrapper = mountingMethod(ComponentWithSlots, { slots: { default: ['{{ foo }}<span>1</span>', 'bar'] }})
195156
if (mountingMethod.name === 'renderToString') {
@@ -289,7 +250,7 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
289250
}
290251
})
291252

292-
itDoNotRunIf(process.env.TEST_ENV === 'node' || isRunningPhantomJS,
253+
itDoNotRunIf(process.env.TEST_ENV === 'node',
293254
'mounts component with default slot if passed string in slot object', () => {
294255
const TestComponent = {
295256
name: 'component-with-slots',
@@ -305,7 +266,7 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
305266
})
306267

307268
itDoNotRunIf(
308-
process.env.TEST_ENV === 'node' || isRunningPhantomJS,
269+
process.env.TEST_ENV === 'node',
309270
'mounts component with named slot if passed string in slot object', () => {
310271
const TestComponent = {
311272
functional: true,
@@ -320,7 +281,7 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
320281
})
321282

322283
itDoNotRunIf(
323-
process.env.TEST_ENV === 'node' || isRunningPhantomJS,
284+
process.env.TEST_ENV === 'node',
324285
'mounts component with named slot if passed string in slot object in array', () => {
325286
const TestComponent = {
326287
functional: true,
@@ -335,7 +296,7 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
335296
})
336297

337298
itDoNotRunIf(
338-
process.env.TEST_ENV === 'node' || isRunningPhantomJS,
299+
process.env.TEST_ENV === 'node',
339300
'mounts component with named slot if passed string in slot object in array', () => {
340301
const TestComponent = {
341302
functional: true,
@@ -350,7 +311,7 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
350311
})
351312

352313
itDoNotRunIf(
353-
process.env.TEST_ENV === 'node' || isRunningPhantomJS,
314+
process.env.TEST_ENV === 'node',
354315
'mounts component with named slot if passed string in slot object in array', () => {
355316
const TestComponent = {
356317
functional: true,
@@ -431,7 +392,7 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
431392
})
432393

433394
itDoNotRunIf(
434-
mountingMethod.name === 'renderToString' || isRunningPhantomJS,
395+
mountingMethod.name === 'renderToString',
435396
'does not error when triggering a click in a slot', () => {
436397
const Parent = {
437398
name: 'Parent',

0 commit comments

Comments
 (0)