diff --git a/docs/api/render.md b/docs/api/render.md
index 6343d6bc5..f54787adf 100644
--- a/docs/api/render.md
+++ b/docs/api/render.md
@@ -13,7 +13,7 @@
- `{Object|Array} stubs`
- `{Vue} localVue`
-- **Returns:** `{CheerioWrapper}`
+- **Returns:** `{Promise}`
- **Options:**
@@ -36,8 +36,8 @@ import { render } from '@vue/server-test-utils'
import Foo from './Foo.vue'
describe('Foo', () => {
- it('renders a div', () => {
- const wrapper = render(Foo)
+ it('renders a div', async () => {
+ const wrapper = await render(Foo)
expect(wrapper.text()).toContain('')
})
})
@@ -50,8 +50,8 @@ import { render } from '@vue/server-test-utils'
import Foo from './Foo.vue'
describe('Foo', () => {
- it('renders a div', () => {
- const wrapper = render(Foo, {
+ it('renders a div', async () => {
+ const wrapper = await render(Foo, {
propsData: {
color: 'red'
}
@@ -70,8 +70,8 @@ import Bar from './Bar.vue'
import FooBar from './FooBar.vue'
describe('Foo', () => {
- it('renders a div', () => {
- const wrapper = render(Foo, {
+ it('renders a div', async () => {
+ const wrapper = await render(Foo, {
slots: {
default: [Bar, FooBar],
fooBar: FooBar, // Will match ,
@@ -90,9 +90,9 @@ import { render } from '@vue/server-test-utils'
import Foo from './Foo.vue'
describe('Foo', () => {
- it('renders a div', () => {
+ it('renders a div', async () => {
const $route = { path: 'http://www.example-path.com' }
- const wrapper = render(Foo, {
+ const wrapper = await render(Foo, {
mocks: {
$route
}
diff --git a/docs/api/renderToString.md b/docs/api/renderToString.md
index 210093794..79ec3458f 100644
--- a/docs/api/renderToString.md
+++ b/docs/api/renderToString.md
@@ -13,7 +13,7 @@
- `{Object|Array} stubs`
- `{Vue} localVue`
-- **Returns:** `{string}`
+- **Returns:** `{Promise}`
- **Options:**
@@ -34,9 +34,9 @@ import { renderToString } from '@vue/server-test-utils'
import Foo from './Foo.vue'
describe('Foo', () => {
- it('renders a div', () => {
- const renderedString = renderToString(Foo)
- expect(renderedString).toContain('')
+ it('renders a div', async () => {
+ const str = await renderToString(Foo)
+ expect(str).toContain('')
})
})
```
@@ -48,13 +48,13 @@ import { renderToString } from '@vue/server-test-utils'
import Foo from './Foo.vue'
describe('Foo', () => {
- it('renders a div', () => {
- const renderedString = renderToString(Foo, {
+ it('renders a div', async () => {
+ const str = await renderToString(Foo, {
propsData: {
color: 'red'
}
})
- expect(renderedString).toContain('red')
+ expect(str).toContain('red')
})
})
```
@@ -68,15 +68,15 @@ import Bar from './Bar.vue'
import FooBar from './FooBar.vue'
describe('Foo', () => {
- it('renders a div', () => {
- const renderedString = renderToString(Foo, {
+ it('renders a div', async () => {
+ const str = await renderToString(Foo, {
slots: {
default: [Bar, FooBar],
fooBar: FooBar, // Will match ,
foo: ''
}
})
- expect(renderedString).toContain('')
+ expect(str).toContain('')
})
})
```
@@ -88,14 +88,14 @@ import { renderToString } from '@vue/server-test-utils'
import Foo from './Foo.vue'
describe('Foo', () => {
- it('renders a div', () => {
+ it('renders a div', async () => {
const $route = { path: 'http://www.example-path.com' }
- const renderedString = renderToString(Foo, {
+ const str = await renderToString(Foo, {
mocks: {
$route
}
})
- expect(renderedString).toContain($route.path)
+ expect(str).toContain($route.path)
})
})
```
diff --git a/docs/ja/api/render.md b/docs/ja/api/render.md
index 88c128d4e..face2c4ff 100644
--- a/docs/ja/api/render.md
+++ b/docs/ja/api/render.md
@@ -13,7 +13,7 @@
- `{Object|Array} stubs`
- `{Vue} localVue`
-- **戻り値:** `{CheerioWrapper}`
+- **戻り値:** `{Promise}`
- **オプション:**
@@ -37,8 +37,8 @@ import { render } from '@vue/server-test-utils'
import Foo from './Foo.vue'
describe('Foo', () => {
- it('renders a div', () => {
- const wrapper = render(Foo)
+ it('renders a div', async () => {
+ const wrapper = await render(Foo)
expect(wrapper.text()).toContain('')
})
})
@@ -51,8 +51,8 @@ import { render } from '@vue/server-test-utils'
import Foo from './Foo.vue'
describe('Foo', () => {
- it('renders a div', () => {
- const wrapper = render(Foo, {
+ it('renders a div', async () => {
+ const wrapper = await render(Foo, {
propsData: {
color: 'red'
}
@@ -71,8 +71,8 @@ import Bar from './Bar.vue'
import FooBar from './FooBar.vue'
describe('Foo', () => {
- it('renders a div', () => {
- const wrapper = render(Foo, {
+ it('renders a div', async () => {
+ const wrapper = await render(Foo, {
slots: {
default: [Bar, FooBar],
fooBar: FooBar, // にマッチします。
@@ -91,9 +91,9 @@ import { render } from '@vue/server-test-utils'
import Foo from './Foo.vue'
describe('Foo', () => {
- it('renders a div', () => {
+ it('renders a div', async () => {
const $route = { path: 'http://www.example-path.com' }
- const wrapper = render(Foo, {
+ const wrapper = await render(Foo, {
mocks: {
$route
}
diff --git a/docs/ja/api/renderToString.md b/docs/ja/api/renderToString.md
index fe3267c05..81381fec1 100644
--- a/docs/ja/api/renderToString.md
+++ b/docs/ja/api/renderToString.md
@@ -13,7 +13,7 @@
- `{Object|Array} stubs`
- `{Vue} localVue`
-- **戻り値:** `{string}`
+- **戻り値:** `{Promise}`
- **オプション:**
@@ -34,9 +34,9 @@ import { renderToString } from '@vue/server-test-utils'
import Foo from './Foo.vue'
describe('Foo', () => {
- it('renders a div', () => {
- const renderedString = renderToString(Foo)
- expect(renderedString).toContain('')
+ it('renders a div', async () => {
+ const str = await renderToString(Foo)
+ expect(str).toContain('')
})
})
```
@@ -48,13 +48,13 @@ import { renderToString } from '@vue/server-test-utils'
import Foo from './Foo.vue'
describe('Foo', () => {
- it('renders a div', () => {
- const renderedString = renderToString(Foo, {
+ it('renders a div', async () => {
+ const str = await renderToString(Foo, {
propsData: {
color: 'red'
}
})
- expect(renderedString).toContain('red')
+ expect(str).toContain('red')
})
})
```
@@ -68,15 +68,15 @@ import Bar from './Bar.vue'
import FooBar from './FooBar.vue'
describe('Foo', () => {
- it('renders a div', () => {
- const renderedString = renderToString(Foo, {
+ it('renders a div', async () => {
+ const str = await renderToString(Foo, {
slots: {
default: [Bar, FooBar],
fooBar: FooBar, // にマッチします。
foo: ''
}
})
- expect(renderedString).toContain('')
+ expect(str).toContain('')
})
})
```
@@ -88,14 +88,14 @@ import { renderToString } from '@vue/server-test-utils'
import Foo from './Foo.vue'
describe('Foo', () => {
- it('renders a div', () => {
+ it('renders a div', async () => {
const $route = { path: 'http://www.example-path.com' }
- const renderedString = renderToString(Foo, {
+ const str = await renderToString(Foo, {
mocks: {
$route
}
})
- expect(renderedString).toContain($route.path)
+ expect(str).toContain($route.path)
})
})
```
diff --git a/docs/ru/api/render.md b/docs/ru/api/render.md
index deb4e4274..fa4574db2 100644
--- a/docs/ru/api/render.md
+++ b/docs/ru/api/render.md
@@ -13,7 +13,7 @@
- `{Object|Array} stubs`
- `{Vue} localVue`
-- **Возвращает:** `{CheerioWrapper}`
+- **Возвращает:** `{Promise}`
- **Опции:**
@@ -36,8 +36,8 @@ import { render } from '@vue/server-test-utils'
import Foo from './Foo.vue'
describe('Foo', () => {
- it('renders a div', () => {
- const wrapper = render(Foo)
+ it('renders a div', async () => {
+ const wrapper = await render(Foo)
expect(wrapper.text()).toContain('')
})
})
@@ -50,8 +50,8 @@ import { render } from '@vue/server-test-utils'
import Foo from './Foo.vue'
describe('Foo', () => {
- it('renders a div', () => {
- const wrapper = render(Foo, {
+ it('renders a div', async () => {
+ const wrapper = await render(Foo, {
propsData: {
color: 'red'
}
@@ -70,8 +70,8 @@ import Bar from './Bar.vue'
import FooBar from './FooBar.vue'
describe('Foo', () => {
- it('renders a div', () => {
- const wrapper = render(Foo, {
+ it('renders a div', async () => {
+ const wrapper = await render(Foo, {
slots: {
default: [Bar, FooBar],
fooBar: FooBar, // Будет соответствовать ,
@@ -90,9 +90,9 @@ import { render } from '@vue/server-test-utils'
import Foo from './Foo.vue'
describe('Foo', () => {
- it('renders a div', () => {
+ it('renders a div', async () => {
const $route = { path: 'http://www.example-path.com' }
- const wrapper = render(Foo, {
+ const wrapper = await render(Foo, {
mocks: {
$route
}
diff --git a/docs/ru/api/renderToString.md b/docs/ru/api/renderToString.md
index 1d052d740..09ce10b04 100644
--- a/docs/ru/api/renderToString.md
+++ b/docs/ru/api/renderToString.md
@@ -13,7 +13,7 @@
- `{Object|Array} stubs`
- `{Vue} localVue`
-- **Возвращает:** `{string}`
+- **Возвращает:** `{Promise}`
- **Опции:**
@@ -34,9 +34,9 @@ import { renderToString } from '@vue/server-test-utils'
import Foo from './Foo.vue'
describe('Foo', () => {
- it('renders a div', () => {
- const renderedString = renderToString(Foo)
- expect(renderedString).toContain('')
+ it('renders a div', async () => {
+ const str = await renderToString(Foo)
+ expect(str).toContain('')
})
})
```
@@ -48,13 +48,13 @@ import { renderToString } from '@vue/server-test-utils'
import Foo from './Foo.vue'
describe('Foo', () => {
- it('renders a div', () => {
- const renderedString = renderToString(Foo, {
+ it('renders a div', async () => {
+ const str = await renderToString(Foo, {
propsData: {
color: 'red'
}
})
- expect(renderedString).toContain('red')
+ expect(str).toContain('red')
})
})
```
@@ -68,15 +68,15 @@ import Bar from './Bar.vue'
import FooBar from './FooBar.vue'
describe('Foo', () => {
- it('renders a div', () => {
- const renderedString = renderToString(Foo, {
+ it('renders a div', async () => {
+ const str = await renderToString(Foo, {
slots: {
default: [Bar, FooBar],
fooBar: FooBar, // Будет соответствовать ,
foo: ''
}
})
- expect(renderedString).toContain('')
+ expect(str).toContain('')
})
})
```
@@ -88,14 +88,14 @@ import { renderToString } from '@vue/server-test-utils'
import Foo from './Foo.vue'
describe('Foo', () => {
- it('renders a div', () => {
+ it('renders a div', async () => {
const $route = { path: 'http://www.example-path.com' }
- const renderedString = renderToString(Foo, {
+ const str = await renderToString(Foo, {
mocks: {
$route
}
})
- expect(renderedString).toContain($route.path)
+ expect(str).toContain($route.path)
})
})
```
diff --git a/docs/zh/api/render.md b/docs/zh/api/render.md
index 4d7469d83..8ec5a9569 100644
--- a/docs/zh/api/render.md
+++ b/docs/zh/api/render.md
@@ -13,7 +13,7 @@
- `{Object|Array} stubs`
- `{Vue} localVue`
-- **返回值:** `{CheerioWrapper}`
+- **返回值:** `{Promise}`
- **选项:**
@@ -36,8 +36,8 @@ import { render } from '@vue/server-test-utils'
import Foo from './Foo.vue'
describe('Foo', () => {
- it('renders a div', () => {
- const wrapper = render(Foo)
+ it('renders a div', async () => {
+ const wrapper = await render(Foo)
expect(wrapper.text()).toContain('')
})
})
@@ -50,8 +50,8 @@ import { render } from '@vue/server-test-utils'
import Foo from './Foo.vue'
describe('Foo', () => {
- it('renders a div', () => {
- const wrapper = render(Foo, {
+ it('renders a div', async () => {
+ const wrapper = await render(Foo, {
propsData: {
color: 'red'
}
@@ -70,8 +70,8 @@ import Bar from './Bar.vue'
import FooBar from './FooBar.vue'
describe('Foo', () => {
- it('renders a div', () => {
- const wrapper = render(Foo, {
+ it('renders a div', async () => {
+ const wrapper = await render(Foo, {
slots: {
default: [Bar, FooBar],
fooBar: FooBar, // Will match ,
@@ -90,9 +90,9 @@ import { render } from '@vue/server-test-utils'
import Foo from './Foo.vue'
describe('Foo', () => {
- it('renders a div', () => {
+ it('renders a div', async () => {
const $route = { path: 'http://www.example-path.com' }
- const wrapper = render(Foo, {
+ const wrapper = await render(Foo, {
mocks: {
$route
}
diff --git a/docs/zh/api/renderToString.md b/docs/zh/api/renderToString.md
index 86e561f7b..98121ead6 100644
--- a/docs/zh/api/renderToString.md
+++ b/docs/zh/api/renderToString.md
@@ -13,7 +13,7 @@
- `{Object|Array} stubs`
- `{Vue} localVue`
-- **返回值:** `{string}`
+- **返回值:** `{Promise}`
- **选项:**
@@ -32,9 +32,9 @@ import { renderToString } from '@vue/server-test-utils'
import Foo from './Foo.vue'
describe('Foo', () => {
- it('renders a div', () => {
- const renderedString = renderToString(Foo)
- expect(renderedString).toContain('')
+ it('renders a div', async () => {
+ const str = await renderToString(Foo)
+ expect(str).toContain('')
})
})
```
@@ -46,13 +46,13 @@ import { renderToString } from '@vue/server-test-utils'
import Foo from './Foo.vue'
describe('Foo', () => {
- it('renders a div', () => {
- const renderedString = renderToString(Foo, {
+ it('renders a div', async () => {
+ const str = await renderToString(Foo, {
propsData: {
color: 'red'
}
})
- expect(renderedString).toContain('red')
+ expect(str).toContain('red')
})
})
```
@@ -66,15 +66,15 @@ import Bar from './Bar.vue'
import FooBar from './FooBar.vue'
describe('Foo', () => {
- it('renders a div', () => {
- const renderedString = renderToString(Foo, {
+ it('renders a div', async () => {
+ const str = await renderToString(Foo, {
slots: {
default: [Bar, FooBar],
fooBar: FooBar, // Will match ,
foo: ''
}
})
- expect(renderedString).toContain('')
+ expect(str).toContain('')
})
})
```
@@ -86,14 +86,14 @@ import { renderToString } from '@vue/server-test-utils'
import Foo from './Foo.vue'
describe('Foo', () => {
- it('renders a div', () => {
+ it('renders a div', async () => {
const $route = { path: 'http://www.example-path.com' }
- const renderedString = renderToString(Foo, {
+ const str = await renderToString(Foo, {
mocks: {
$route
}
})
- expect(renderedString).toContain($route.path)
+ expect(str).toContain($route.path)
})
})
```
diff --git a/package.json b/package.json
index ed4dc1ded..15b5f907b 100644
--- a/package.json
+++ b/package.json
@@ -26,7 +26,7 @@
"test:unit:debug": "npm run build:test && node --inspect-brk node_modules/.bin/mocha-webpack --webpack-config test/setup/webpack.test.config.js test/specs --recursive --require test/setup/mocha.setup.js",
"test:unit:karma": "npm run build:test && TARGET=browser karma start test/setup/karma.conf.js --single-run",
"test:unit:node": "npm run build:test && npm run test:unit:node:only",
- "test:unit:node:only": "cross-env TEST_ENV=node mocha-webpack --webpack-config test/setup/webpack.test.config.js test/specs --recursive --require test/setup/mocha.setup.js",
+ "test:unit:node:only": "cross-env TEST_ENV=node mocha-webpack --webpack-config test/setup/webpack.test.config.js test/specs/render.spec.js test/specs/renderToString.spec.js --require test/setup/mocha.setup.js",
"test:types": "tsc -p packages/test-utils/types && tsc -p packages/server-test-utils/types"
},
"devDependencies": {
diff --git a/packages/server-test-utils/src/render.js b/packages/server-test-utils/src/render.js
index cd5fea340..d819efa08 100644
--- a/packages/server-test-utils/src/render.js
+++ b/packages/server-test-utils/src/render.js
@@ -6,7 +6,6 @@ import cheerio from 'cheerio'
export default function render(
component: Component,
options: Options = {}
-): string {
- const renderedString = renderToString(component, options)
- return cheerio.load('')(renderedString)
+): Promise {
+ return renderToString(component, options).then(str => cheerio.load('')(str))
}
diff --git a/packages/server-test-utils/src/renderToString.js b/packages/server-test-utils/src/renderToString.js
index 9b8ac5dc7..c6d0b11b5 100644
--- a/packages/server-test-utils/src/renderToString.js
+++ b/packages/server-test-utils/src/renderToString.js
@@ -15,17 +15,17 @@ Vue.config.devtools = false
export default function renderToString(
component: Component,
options: Options = {}
-): string {
+): Promise {
const renderer = createRenderer()
if (!renderer) {
throwError(
- `renderToString must be run in node. It cannot be ` + `run in a browser`
+ `renderToString must be run in node. It cannot be run in a browser`
)
}
if (options.attachToDocument) {
- throwError(`you cannot use attachToDocument with ` + `renderToString`)
+ throwError(`you cannot use attachToDocument with renderToString`)
}
const mergedOptions = mergeOptions(options, config)
@@ -36,14 +36,6 @@ export default function renderToString(
mergedOptions,
testUtils.createLocalVue(options.localVue)
)
- let renderedString = ''
-
- // $FlowIgnore
- renderer.renderToString(vm, (err, res) => {
- if (err) {
- throw err
- }
- renderedString = res
- })
- return renderedString
+
+ return renderer.renderToString(vm)
}
diff --git a/packages/server-test-utils/types/index.d.ts b/packages/server-test-utils/types/index.d.ts
index 936cddfa1..abb1d13c4 100644
--- a/packages/server-test-utils/types/index.d.ts
+++ b/packages/server-test-utils/types/index.d.ts
@@ -54,10 +54,10 @@ interface VueTestUtilsConfigOptions {
export declare let config: VueTestUtilsConfigOptions
-export declare function render (component: VueClass, options?: ThisTypedMountOptions): Cheerio
-export declare function render (component: ComponentOptions, options?: ThisTypedMountOptions): Cheerio
-export declare function render (component: FunctionalComponentOptions, options?: MountOptions): Cheerio
+export declare function render (component: VueClass, options?: ThisTypedMountOptions): Promise
+export declare function render (component: ComponentOptions, options?: ThisTypedMountOptions): Promise
+export declare function render (component: FunctionalComponentOptions, options?: MountOptions): Promise
-export declare function renderToString (component: VueClass, options?: ThisTypedMountOptions): string
-export declare function renderToString (component: ComponentOptions, options?: ThisTypedMountOptions): string
-export declare function renderToString (component: FunctionalComponentOptions, options?: MountOptions): string
+export declare function renderToString (component: VueClass, options?: ThisTypedMountOptions): Promise
+export declare function renderToString (component: ComponentOptions, options?: ThisTypedMountOptions): Promise
+export declare function renderToString (component: FunctionalComponentOptions, options?: MountOptions): Promise
diff --git a/packages/server-test-utils/types/test/renderToString.ts b/packages/server-test-utils/types/test/renderToString.ts
index a4259b1e2..8e5e70c94 100644
--- a/packages/server-test-utils/types/test/renderToString.ts
+++ b/packages/server-test-utils/types/test/renderToString.ts
@@ -4,17 +4,22 @@ import { normalOptions, functionalOptions, Normal, ClassComponent } from './reso
const store = new Vuex.Store({})
-const renderResult: Cheerio = render(
- {
- template: 'foo
'
- },
- {
- attachToDocument: true,
- scopedSlots: {
- foo: `Foo
`
+async function test () {
+ const renderResult: Cheerio = await render(
+ {
+ template: 'foo
'
+ },
+ {
+ attachToDocument: true,
+ scopedSlots: {
+ foo: `Foo
`
+ }
}
- }
-)
+ )
+ const str: string = await renderToString(ClassComponent)
+}
+
+test()
renderToString(ClassComponent, {
mocks: {
diff --git a/test/specs/mounting-options/attrs.spec.js b/test/specs/mounting-options/attrs.spec.js
index 5394bc305..c0282f82a 100644
--- a/test/specs/mounting-options/attrs.spec.js
+++ b/test/specs/mounting-options/attrs.spec.js
@@ -1,16 +1,14 @@
import { attrsSupported } from '~resources/utils'
import {
- describeWithMountingMethods,
+ describeWithShallowAndMount,
isRunningPhantomJS,
vueVersion
} from '~resources/utils'
import { itSkipIf, itDoNotRunIf } from 'conditional-specs'
-describeWithMountingMethods('options.attrs', mountingMethod => {
+describeWithShallowAndMount('options.attrs', mountingMethod => {
itDoNotRunIf(
- vueVersion < 2.4 ||
- mountingMethod.name === 'renderToString' ||
- isRunningPhantomJS,
+ vueVersion < 2.4 || isRunningPhantomJS,
'handles inherit attrs',
() => {
if (!attrsSupported) return
@@ -28,7 +26,7 @@ describeWithMountingMethods('options.attrs', mountingMethod => {
)
itSkipIf(
- mountingMethod.name === 'renderToString' || vueVersion < 2.5,
+ vueVersion < 2.5,
'defines attrs as empty object even when not passed',
() => {
const wrapper = mountingMethod({ template: '' })
diff --git a/test/specs/mounting-options/context.spec.js b/test/specs/mounting-options/context.spec.js
index 621559e68..0c2a506ae 100644
--- a/test/specs/mounting-options/context.spec.js
+++ b/test/specs/mounting-options/context.spec.js
@@ -1,30 +1,28 @@
import Vue from 'vue'
import { vueVersion } from '~resources/utils'
-import { describeWithMountingMethods } from '~resources/utils'
+import { describeWithShallowAndMount } from '~resources/utils'
+import { itDoNotRunIf } from 'conditional-specs'
-describeWithMountingMethods('options.context', mountingMethod => {
- it('mounts functional component when passed context object', () => {
- if (vueVersion <= 2.2) {
- console.log(
- 'WARN: no current way to test functional component in vue@2.1'
- )
- return
- }
+describeWithShallowAndMount('options.context', mountingMethod => {
+ itDoNotRunIf(
+ vueVersion <= 2.2,
+ 'mounts functional component when passed context object',
+ () => {
+ const Component = {
+ functional: true,
+ render(h, { props }) {
+ return h('div')
+ },
+ name: 'common'
+ }
+ const context = {
+ data: { hello: true },
+ props: { show: true }
+ }
- const Component = {
- functional: true,
- render(h, { props }) {
- return h('div')
- },
- name: 'common'
- }
- const context = {
- data: { hello: true },
- props: { show: true }
+ mountingMethod(Component, { context })
}
-
- mountingMethod(Component, { context })
- })
+ )
it('throws error if non functional component is passed with context option', () => {
const Component = {
@@ -76,9 +74,7 @@ describeWithMountingMethods('options.context', mountingMethod => {
render: (h, { props }) => h('div', props.testProp)
}
const wrapper = mountingMethod(Component)
- const HTML =
- mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
- expect(HTML).to.contain(defaultValue)
+ expect(wrapper.html()).to.contain(defaultValue)
})
it('mounts functional component with a defined context.children text', () => {
@@ -93,9 +89,7 @@ describeWithMountingMethods('options.context', mountingMethod => {
children: ['render text']
}
})
- const HTML =
- mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
- expect(HTML).to.contain('render text')
+ expect(wrapper.html()).to.contain('render text')
})
it('mounts functional component with a defined context.children element', () => {
@@ -110,8 +104,6 @@ describeWithMountingMethods('options.context', mountingMethod => {
children: [h => h('div', 'render component')]
}
})
- const HTML =
- mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
- expect(HTML).to.contain('render component')
+ expect(wrapper.html()).to.contain('render component')
})
})
diff --git a/test/specs/mounting-options/localVue.spec.js b/test/specs/mounting-options/localVue.spec.js
index b2614bd51..f78eeab44 100644
--- a/test/specs/mounting-options/localVue.spec.js
+++ b/test/specs/mounting-options/localVue.spec.js
@@ -1,6 +1,6 @@
import Vue from 'vue'
import {
- describeWithMountingMethods,
+ describeWithShallowAndMount,
isRunningPhantomJS,
vueVersion
} from '~resources/utils'
@@ -8,7 +8,7 @@ import { createLocalVue, shallowMount, mount } from '~vue/test-utils'
import { itSkipIf, itRunIf, itDoNotRunIf } from 'conditional-specs'
import Vuex from 'vuex'
-describeWithMountingMethods('options.localVue', mountingMethod => {
+describeWithShallowAndMount('options.localVue', mountingMethod => {
itSkipIf(
isRunningPhantomJS,
'mounts component using passed localVue as base Vue',
@@ -21,9 +21,7 @@ describeWithMountingMethods('options.localVue', mountingMethod => {
const wrapper = mountingMethod(TestComponent, {
localVue: localVue
})
- const HTML =
- mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
- expect(HTML).to.contain('some value')
+ expect(wrapper.html()).to.contain('some value')
}
)
diff --git a/test/specs/mounting-options/methods.spec.js b/test/specs/mounting-options/methods.spec.js
index c95d6e6d4..352f1643c 100644
--- a/test/specs/mounting-options/methods.spec.js
+++ b/test/specs/mounting-options/methods.spec.js
@@ -1,14 +1,12 @@
import { config } from '~vue/test-utils'
-import { describeWithMountingMethods } from '~resources/utils'
+import { describeWithShallowAndMount } from '~resources/utils'
-describeWithMountingMethods('options.methods', mountingMethod => {
+describeWithShallowAndMount('options.methods', mountingMethod => {
it('prioritize mounting options over config', () => {
config.methods['val'] = () => 'methodFromConfig'
const TestComponent = {
- template: `
- {{ val() }}
- `
+ template: `{{ val() }}
`
}
const wrapper = mountingMethod(TestComponent, {
@@ -18,8 +16,7 @@ describeWithMountingMethods('options.methods', mountingMethod => {
}
}
})
- const HTML =
- mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
- expect(HTML).to.contain('methodFromOptions')
+
+ expect(wrapper.html()).to.contain('methodFromOptions')
})
})
diff --git a/test/specs/mounting-options/mocks.spec.js b/test/specs/mounting-options/mocks.spec.js
index 91cbb6a52..e8478c463 100644
--- a/test/specs/mounting-options/mocks.spec.js
+++ b/test/specs/mounting-options/mocks.spec.js
@@ -2,10 +2,10 @@ import { createLocalVue, config } from '~vue/test-utils'
import Vue from 'vue'
import Component from '~resources/components/component.vue'
import ComponentWithVuex from '~resources/components/component-with-vuex.vue'
-import { describeWithMountingMethods, vueVersion } from '~resources/utils'
+import { describeWithShallowAndMount, vueVersion } from '~resources/utils'
import { itDoNotRunIf, itSkipIf, itRunIf } from 'conditional-specs'
-describeWithMountingMethods('options.mocks', mountingMethod => {
+describeWithShallowAndMount('options.mocks', mountingMethod => {
const sandbox = sinon.createSandbox()
let configMocksSave
@@ -38,10 +38,8 @@ describeWithMountingMethods('options.mocks', mountingMethod => {
$route
}
})
- const HTML =
- mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
- expect(HTML).contains('true')
- expect(HTML).contains('http://test.com')
+ expect(wrapper.html()).contains('true')
+ expect(wrapper.html()).contains('http://test.com')
})
itSkipIf(vueVersion < 2.3, 'adds variables to extended components', () => {
@@ -61,46 +59,35 @@ describeWithMountingMethods('options.mocks', mountingMethod => {
$route
}
})
- const HTML =
- mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
- expect(HTML).contains('http://test.com')
+ expect(wrapper.html()).contains('http://test.com')
})
- // render returns a string so reactive does not apply
- itDoNotRunIf(
- mountingMethod.name === 'renderToString',
- 'adds variables as reactive properties to vm when passed',
- async () => {
- const stub = sandbox.stub()
- const $reactiveMock = { value: 'value' }
- const wrapper = mountingMethod(
- {
- template: `
-
- {{value}}
-
- `,
- computed: {
- value() {
- return this.$reactiveMock.value
- }
- },
- watch: {
- value() {
- stub()
- }
+ it('adds variables as reactive properties to vm when passed', async () => {
+ const stub = sandbox.stub()
+ const $reactiveMock = { value: 'value' }
+ const wrapper = mountingMethod(
+ {
+ template: `{{value}}
`,
+ computed: {
+ value() {
+ return this.$reactiveMock.value
}
},
- {
- mocks: { $reactiveMock }
+ watch: {
+ value() {
+ stub()
+ }
}
- )
- expect(wrapper.text()).to.contain('value')
- $reactiveMock.value = 'changed value'
- await Vue.nextTick()
- expect(wrapper.text()).to.contain('changed value')
- }
- )
+ },
+ {
+ mocks: { $reactiveMock }
+ }
+ )
+ expect(wrapper.text()).to.contain('value')
+ $reactiveMock.value = 'changed value'
+ await Vue.nextTick()
+ expect(wrapper.text()).to.contain('changed value')
+ })
itDoNotRunIf(
mountingMethod.name === 'shallowMount',
@@ -118,9 +105,7 @@ describeWithMountingMethods('options.mocks', mountingMethod => {
mocks: { $store: { state: { count, foo: {} } } }
}
)
- const HTML =
- mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
- expect(HTML).contains(count)
+ expect(wrapper.html()).contains(count)
}
)
@@ -142,27 +127,21 @@ describeWithMountingMethods('options.mocks', mountingMethod => {
localVue
}
)
- const HTML =
- mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
- expect(HTML).contains(count)
+ expect(wrapper.html()).contains(count)
}
)
- itDoNotRunIf(
- mountingMethod.name === 'renderToString',
- 'does not affect global vue class when passed as mocks object',
- () => {
- const $store = { store: true }
- const wrapper = mountingMethod(Component, {
- mocks: {
- $store
- }
- })
- expect(wrapper.vm.$store).to.equal($store)
- const freshWrapper = mountingMethod(Component)
- expect(typeof freshWrapper.vm.$store).to.equal('undefined')
- }
- )
+ it('does not affect global vue class when passed as mocks object', () => {
+ const $store = { store: true }
+ const wrapper = mountingMethod(Component, {
+ mocks: {
+ $store
+ }
+ })
+ expect(wrapper.vm.$store).to.equal($store)
+ const freshWrapper = mountingMethod(Component)
+ expect(typeof freshWrapper.vm.$store).to.equal('undefined')
+ })
it('logs that a property cannot be overwritten if there are problems writing', () => {
const localVue = createLocalVue()
@@ -197,9 +176,7 @@ describeWithMountingMethods('options.mocks', mountingMethod => {
$global: 'locallyMockedValue'
}
})
- const HTML =
- mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
- expect(HTML).to.contain('locallyMockedValue')
+ expect(wrapper.html()).to.contain('locallyMockedValue')
})
itRunIf(
diff --git a/test/specs/mounting-options/parentComponent.spec.js b/test/specs/mounting-options/parentComponent.spec.js
index f6eb82735..5ce65f3dc 100644
--- a/test/specs/mounting-options/parentComponent.spec.js
+++ b/test/specs/mounting-options/parentComponent.spec.js
@@ -1,6 +1,6 @@
-import { describeWithMountingMethods } from '~resources/utils'
+import { describeWithShallowAndMount } from '~resources/utils'
-describeWithMountingMethods('options.parentComponent', mountingMethod => {
+describeWithShallowAndMount('options.parentComponent', mountingMethod => {
it('mounts component with $parent set to options.parentComponent', () => {
const Parent = {
data: () => ({
@@ -13,9 +13,7 @@ describeWithMountingMethods('options.parentComponent', mountingMethod => {
const wrapper = mountingMethod(TestComponent, {
parentComponent: Parent
})
- const HTML =
- mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
- expect(HTML).to.contain('Parent Name')
+ expect(wrapper.html()).to.contain('Parent Name')
})
it('validates parentComponent option', () => {
diff --git a/test/specs/mounting-options/provide.spec.js b/test/specs/mounting-options/provide.spec.js
index eb356f81d..97bb9d32c 100644
--- a/test/specs/mounting-options/provide.spec.js
+++ b/test/specs/mounting-options/provide.spec.js
@@ -1,10 +1,10 @@
import { config } from '~vue/test-utils'
import ComponentWithInject from '~resources/components/component-with-inject.vue'
import { injectSupported } from '~resources/utils'
-import { describeWithMountingMethods } from '~resources/utils'
+import { describeWithShallowAndMount } from '~resources/utils'
import { itDoNotRunIf, itSkipIf } from 'conditional-specs'
-describeWithMountingMethods('options.provide', mountingMethod => {
+describeWithShallowAndMount('options.provide', mountingMethod => {
let configProvideSave
beforeEach(() => {
@@ -25,9 +25,7 @@ describeWithMountingMethods('options.provide', mountingMethod => {
const wrapper = mountingMethod(ComponentWithInject, {
provide: { fromMount: 'objectValue' }
})
- const HTML =
- mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
- expect(HTML).to.contain('objectValue')
+ expect(wrapper.html()).to.contain('objectValue')
}
)
@@ -42,9 +40,7 @@ describeWithMountingMethods('options.provide', mountingMethod => {
}
}
})
- const HTML =
- mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
- expect(HTML).to.contain('functionValue')
+ expect(wrapper.html()).to.contain('functionValue')
}
)
@@ -72,10 +68,7 @@ describeWithMountingMethods('options.provide', mountingMethod => {
config.provide['fromMount'] = 'globalConfig'
const wrapper = mountingMethod(ComponentWithInject)
- const HTML =
- mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
-
- expect(HTML).to.contain('globalConfig')
+ expect(wrapper.html()).to.contain('globalConfig')
}
)
@@ -88,24 +81,18 @@ describeWithMountingMethods('options.provide', mountingMethod => {
const wrapper = mountingMethod(ComponentWithInject, {
provide: { fromMount: '_' }
})
- const HTML =
- mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
- expect(HTML).to.contain('_')
+ expect(wrapper.html()).to.contain('_')
}
)
- itSkipIf(
- mountingMethod.name === 'renderToString',
- 'config with function throws',
- () => {
- config.provide = () => {}
+ it('config with function throws', () => {
+ config.provide = () => {}
- expect(() => {
- mountingMethod(ComponentWithInject, {
- provide: { fromMount: '_' }
- })
- }).to.throw()
- }
- )
+ expect(() => {
+ mountingMethod(ComponentWithInject, {
+ provide: { fromMount: '_' }
+ })
+ }).to.throw()
+ })
})
diff --git a/test/specs/mounting-options/slots.spec.js b/test/specs/mounting-options/slots.spec.js
index 423d50bf6..ee399c333 100644
--- a/test/specs/mounting-options/slots.spec.js
+++ b/test/specs/mounting-options/slots.spec.js
@@ -3,20 +3,16 @@ import Component from '~resources/components/component.vue'
import ComponentWithSlots from '~resources/components/component-with-slots.vue'
import ComponentAsAClass from '~resources/components/component-as-a-class.vue'
import ComponentWithParentName from '~resources/components/component-with-parent-name.vue'
-import { describeWithMountingMethods, vueVersion } from '~resources/utils'
-import { itSkipIf, itDoNotRunIf } from 'conditional-specs'
+import { describeWithShallowAndMount, vueVersion } from '~resources/utils'
+import { itDoNotRunIf } from 'conditional-specs'
import { mount, createLocalVue } from '~vue/test-utils'
-describeWithMountingMethods('options.slots', mountingMethod => {
+describeWithShallowAndMount('options.slots', mountingMethod => {
it('mounts component with default slot if passed component in slot object', () => {
const wrapper = mountingMethod(ComponentWithSlots, {
slots: { default: Component }
})
- if (mountingMethod.name === 'renderToString') {
- expect(wrapper).contains('')
- } else {
- expect(wrapper.contains(Component)).to.equal(true)
- }
+ expect(wrapper.contains(Component)).to.equal(true)
})
itDoNotRunIf(
@@ -37,11 +33,7 @@ describeWithMountingMethods('options.slots', mountingMethod => {
},
localVue
})
- if (mountingMethod.name === 'renderToString') {
- expect(wrapper).contains('
')
})
it('handles components without a render function', () => {
@@ -452,9 +413,7 @@ describeWithMountingMethods('options.stub', mountingMethod => {
'stub-component': StubComponent
}
})
- const HTML =
- mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
- expect(HTML).contains('No render function')
+ expect(wrapper.html()).contains('No render function')
})
it('throws an error when passed a circular reference', () => {
@@ -561,41 +520,30 @@ describeWithMountingMethods('options.stub', mountingMethod => {
DynamicHello3: StubComponent
}
})
- const HTML =
- mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
-
- expect(HTML).to.contain('span')
- expect(HTML).to.contain(
- mountingMethod.name === 'renderToString'
- ? 'DynamicHello2-stub'
- : 'dynamichello2-stub'
- )
- expect(HTML).to.contain('h1')
+ expect(wrapper.html()).to.contain('span')
+ expect(wrapper.html()).to.contain('dynamichello2-stub')
+ expect(wrapper.html()).to.contain('h1')
})
- itDoNotRunIf(
- mountingMethod.name === 'renderToString',
- 'uses original component stub',
- () => {
- const Stub = {
- template: ''
- }
- const ToStub = {
- template: ''
- }
- const TestComponent = {
- template: '
',
- components: {
- ToStub
- }
+ it('uses original component stub', () => {
+ const Stub = {
+ template: ''
+ }
+ const ToStub = {
+ template: ''
+ }
+ const TestComponent = {
+ template: '
',
+ components: {
+ ToStub
}
- const wrapper = mountingMethod(TestComponent, {
- stubs: {
- ToStub: Stub
- }
- })
- expect(wrapper.find(ToStub).exists()).to.be.false
- expect(wrapper.find(Stub).exists()).to.be.true
}
- )
+ const wrapper = mountingMethod(TestComponent, {
+ stubs: {
+ ToStub: Stub
+ }
+ })
+ expect(wrapper.find(ToStub).exists()).to.be.false
+ expect(wrapper.find(Stub).exists()).to.be.true
+ })
})
diff --git a/test/specs/render.spec.js b/test/specs/render.spec.js
index 8f13ce36c..70f355f30 100644
--- a/test/specs/render.spec.js
+++ b/test/specs/render.spec.js
@@ -1,12 +1,13 @@
import { render } from '~vue/server-test-utils'
import Cheerio from 'cheerio'
+import { describeDoNotRunIf } from 'conditional-specs'
-describe('render', () => {
- it('returns a cheerio wrapper of the rendered component', () => {
+describeDoNotRunIf(process.env.TEST_ENV !== 'node', 'render', () => {
+ it('returns a cheerio wrapper of the rendered component', async () => {
const TestComponent = {
template: ''
}
- const wrapper = render(TestComponent)
+ const wrapper = await render(TestComponent)
expect(wrapper).to.be.an.instanceof(Cheerio)
expect(wrapper.find('h2').text()).to.equal('Test')
expect(wrapper.find('p').length).to.equal(2)
diff --git a/test/specs/renderToString.spec.js b/test/specs/renderToString.spec.js
index 156df6132..31c112a7f 100644
--- a/test/specs/renderToString.spec.js
+++ b/test/specs/renderToString.spec.js
@@ -1,15 +1,90 @@
import { renderToString } from '~vue/server-test-utils'
-import Component from '~resources/components/component.vue'
-import { isRunningJSDOM } from '~resources/utils'
-import { itDoNotRunIf } from 'conditional-specs'
-
-describe.skip('renderToString', () => {
- itDoNotRunIf(isRunningJSDOM, 'throws error when not run in node', () => {
- const fn = () => renderToString(Component)
- const message =
- '[vue-test-utils]: renderToString must be run in node. It cannot be run in a browser'
- expect(fn)
- .to.throw()
- .with.property('message', message)
+import { createLocalVue } from '~vue/test-utils'
+import ComponentWithChild from '~resources/components/component-with-child.vue'
+import { describeDoNotRunIf } from 'conditional-specs'
+
+describeDoNotRunIf(process.env.TEST_ENV !== 'node', 'renderToString', () => {
+ it('returns a promise', async () => {
+ const str = await renderToString({
+ template: `{{this.val}}
`,
+ data() {
+ return { val: '123' }
+ }
+ })
+ expect(str).to.contain('123')
+ })
+
+ it('mounts functional component with a defined context when no context object passed in options', async () => {
+ const defaultValue = '[vue-test-utils]: testProp default value'
+ const Component = {
+ functional: true,
+ props: {
+ testProp: {
+ type: String,
+ default: defaultValue
+ }
+ },
+ render: (h, { props }) => h('div', props.testProp)
+ }
+ const str = await renderToString(Component)
+ expect(str).to.contain(defaultValue)
+ })
+
+ it('mounts component using passed localVue as base Vue', async () => {
+ const TestComponent = {
+ template: `{{test}}
`
+ }
+ const localVue = createLocalVue()
+ localVue.prototype.test = 'some value'
+ const str = await renderToString(TestComponent, {
+ localVue: localVue
+ })
+ expect(str).to.contain('some value')
+ })
+
+ it('adds variables to vm when passed', async () => {
+ const TestComponent = {
+ template: `
+
+ {{$store.store}}
+ {{$route.path}}
+
+ `
+ }
+ const $store = { store: true }
+ const $route = { path: 'http://test.com' }
+ const str = await renderToString(TestComponent, {
+ mocks: {
+ $store,
+ $route
+ }
+ })
+ expect(str).contains('true')
+ expect(str).contains('http://test.com')
+ })
+
+ it('mounts component with $parent set to options.parentComponent', async () => {
+ const Parent = {
+ data: () => ({
+ customName: 'Parent Name'
+ })
+ }
+ const TestComponent = {
+ template: '{{$parent.customName}}
'
+ }
+ const str = await renderToString(TestComponent, {
+ parentComponent: Parent
+ })
+ expect(str).to.contain('Parent Name')
+ })
+
+ it('replaces component with template string ', async () => {
+ const str = await renderToString(ComponentWithChild, {
+ stubs: {
+ ChildComponent: ''
+ }
+ })
+
+ expect(str).to.contain('"stub"')
})
})