Skip to content

Commit 1b4c888

Browse files
authored
docs: add render method to docs (#485)
1 parent 5b59e69 commit 1b4c888

File tree

5 files changed

+112
-4
lines changed

5 files changed

+112
-4
lines changed

docs/en/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Vue Test Utils is the official unit testing utility library for Vue.js.
1818
* [API](api/README.md)
1919
* [mount](api/mount.md)
2020
* [shallow](api/shallow.md)
21+
* [render](api/render.md)
2122
* [renderToString](api/renderToString.md)
2223
* [Mounting Options](api/options.md)
2324
- [context](api/options.md#context)

docs/en/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* [API](api/README.md)
1515
* [mount](api/mount.md)
1616
* [shallow](api/shallow.md)
17+
* [render](api/render.md)
1718
* [renderToString](api/renderToString.md)
1819
* [Mounting Options](api/options.md)
1920
- [context](api/options.md#context)

docs/en/api/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* [mount](./mount.md)
44
* [shallow](./shallow.md)
5+
* [render](./render.md)
56
* [renderToString](./renderToString.md)
67
* [Mounting Options](./options.md)
78
- [context](./options.md#context)

docs/en/api/render.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# `render(component {, options}])`
2+
3+
- **Arguments:**
4+
5+
- `{Component} component`
6+
- `{Object} options`
7+
- `{Object} context`
8+
- `{Array<Component|Object>|Component} children`
9+
- `{Object} slots`
10+
- `{Array<Componet|Object>|Component|String} default`
11+
- `{Array<Componet|Object>|Component|String} named`
12+
- `{Object} mocks`
13+
- `{Object|Array<string>} stubs`
14+
- `{Vue} localVue`
15+
16+
- **Returns:** `{CheerioWrapper}`
17+
18+
- **Options:**
19+
20+
See [options](./options.md)
21+
22+
- **Usage:**
23+
24+
Renders an object to a string and returns a [cheerio wrapper](https://github.com/cheeriojs/cheerio).
25+
26+
Cheerio is a jQuery-like library to traverse the DOM in Node.js. It has a similar API to the Vue Test Utils [`Wrapper`](wrapper/README.md).
27+
28+
`render` uses [`vue-server-renderer`](https://ssr.vuejs.org/en/basic.html) under the hood, to render a component to static HTML.
29+
30+
`render` is included in the `@vue/server-test-utils` package.
31+
32+
**Without options:**
33+
34+
```js
35+
import { render } from '@vue/server-test-utils'
36+
import Foo from './Foo.vue'
37+
38+
describe('Foo', () => {
39+
it('renders a div', () => {
40+
const wrapper = render(Foo)
41+
expect(wrapper.text()).toContain('<div></div>')
42+
})
43+
})
44+
```
45+
46+
**With Vue options:**
47+
48+
```js
49+
import { render } from '@vue/server-test-utils'
50+
import Foo from './Foo.vue'
51+
52+
describe('Foo', () => {
53+
it('renders a div', () => {
54+
const wrapper = render(Foo, {
55+
propsData: {
56+
color: 'red'
57+
}
58+
})
59+
expect(wrapper.text()).toContain('red')
60+
})
61+
})
62+
```
63+
64+
**Default and named slots:**
65+
66+
```js
67+
import { render } from '@vue/server-test-utils'
68+
import Foo from './Foo.vue'
69+
import Bar from './Bar.vue'
70+
import FooBar from './FooBar.vue'
71+
72+
describe('Foo', () => {
73+
it('renders a div', () => {
74+
const wrapper = render(Foo, {
75+
slots: {
76+
default: [Bar, FooBar],
77+
fooBar: FooBar, // Will match <slot name="FooBar" />,
78+
foo: '<div />'
79+
}
80+
})
81+
expect(wrapper.text()).toContain('<div></div>')
82+
})
83+
})
84+
```
85+
86+
**Stubbing global properties:**
87+
88+
```js
89+
import { render } from '@vue/server-test-utils'
90+
import Foo from './Foo.vue'
91+
92+
describe('Foo', () => {
93+
it('renders a div', () => {
94+
const $route = { path: 'http://www.example-path.com' }
95+
const wrapper = render(Foo, {
96+
mocks: {
97+
$route
98+
}
99+
})
100+
expect(wrapper.text()).toContain($route.path)
101+
})
102+
})
103+
```

docs/en/api/renderToString.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ Renders a component to HTML.
2525

2626
`renderToString` uses [`vue-server-renderer`](https://ssr.vuejs.org/en/basic.html) under the hood, to render a component to HTML.
2727

28+
`renderToString` is included in the `@vue/server-test-utils` package.
29+
2830
**Without options:**
2931

3032
```js
31-
import { renderToString } from '@vue/test-utils'
33+
import { renderToString } from '@vue/server-test-utils'
3234
import Foo from './Foo.vue'
3335

3436
describe('Foo', () => {
@@ -42,7 +44,7 @@ describe('Foo', () => {
4244
**With Vue options:**
4345

4446
```js
45-
import { renderToString } from '@vue/test-utils'
47+
import { renderToString } from '@vue/server-test-utils'
4648
import Foo from './Foo.vue'
4749

4850
describe('Foo', () => {
@@ -60,7 +62,7 @@ describe('Foo', () => {
6062
**Default and named slots:**
6163

6264
```js
63-
import { renderToString } from '@vue/test-utils'
65+
import { renderToString } from '@vue/server-test-utils'
6466
import Foo from './Foo.vue'
6567
import Bar from './Bar.vue'
6668
import FooBar from './FooBar.vue'
@@ -82,7 +84,7 @@ describe('Foo', () => {
8284
**Stubbing global properties:**
8385

8486
```js
85-
import { renderToString } from '@vue/test-utils'
87+
import { renderToString } from '@vue/server-test-utils'
8688
import Foo from './Foo.vue'
8789

8890
describe('Foo', () => {

0 commit comments

Comments
 (0)