Skip to content

Commit 290be49

Browse files
38elementseddyerburgh
authored andcommitted
docs: update README.md (#588)
1 parent 33a6731 commit 290be49

34 files changed

+129
-129
lines changed

docs/en/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Vue Test Utils is the official unit testing utility library for Vue.js.
1717
* [Using with Vuex](guides/using-with-vuex.md)
1818
* [API](api/README.md)
1919
* [mount](api/mount.md)
20-
* [shallow](api/shallow.md)
20+
* [shallowMount](api/shallowMount.md)
2121
* [render](api/render.md)
2222
* [renderToString](api/renderToString.md)
2323
* [Mounting Options](api/options.md)

docs/en/SUMMARY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* [Using with Vuex](guides/using-with-vuex.md)
1414
* [API](api/README.md)
1515
* [mount](api/mount.md)
16-
* [shallow](api/shallow.md)
16+
* [shallowMount](api/shallowMount.md)
1717
* [render](api/render.md)
1818
* [renderToString](api/renderToString.md)
1919
* [Mounting Options](api/options.md)

docs/en/api/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# API
22

33
* [mount](./mount.md)
4-
* [shallow](./shallow.md)
4+
* [shallowMount](./shallowMount.md)
55
* [render](./render.md)
66
* [renderToString](./renderToString.md)
77
* [Mounting Options](./options.md)

docs/en/api/createLocalVue.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
Use it with `options.localVue`:
1111

1212
```js
13-
import { createLocalVue, shallow } from '@vue/test-utils'
13+
import { createLocalVue, shallowMount } from '@vue/test-utils'
1414
import Foo from './Foo.vue'
1515

1616
const localVue = createLocalVue()
17-
const wrapper = shallow(Foo, {
17+
const wrapper = shallowMount(Foo, {
1818
localVue,
1919
mocks: { foo: true }
2020
})
2121
expect(wrapper.vm.foo).toBe(true)
2222

23-
const freshWrapper = shallow(Foo)
23+
const freshWrapper = shallowMount(Foo)
2424
expect(freshWrapper.vm.foo).toBe(false)
2525
```
2626

docs/en/api/options.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Mounting Options
22

3-
Options for `mount` and `shallow`. The options object can contain both Vue Test Utils mounting options and other options.
3+
Options for `mount` and `shallowMount`. The options object can contain both Vue Test Utils mounting options and other options.
44

55
## Vue Test Utils Specific Mounting Options
66

@@ -50,7 +50,7 @@ Example:
5050
import Foo from './Foo.vue'
5151
import Bar from './Bar.vue'
5252

53-
const wrapper = shallow(Component, {
53+
const wrapper = shallowMount(Component, {
5454
slots: {
5555
default: [Foo, Bar],
5656
fooBar: Foo, // Will match `<slot name="FooBar" />`.
@@ -87,7 +87,7 @@ You can use [Puppeteer](https://github.com/karma-runner/karma-chrome-launcher#he
8787
Example:
8888

8989
```js
90-
const wrapper = shallow(Component, {
90+
const wrapper = shallowMount(Component, {
9191
scopedSlots: {
9292
foo: '<p slot-scope="props">{{props.index}},{{props.text}}</p>'
9393
}
@@ -110,7 +110,7 @@ mount(Component, {
110110
stubs: ['registered-component']
111111
})
112112

113-
shallow(Component, {
113+
shallowMount(Component, {
114114
stubs: {
115115
// stub with a specific implementation
116116
'registered-component': Foo,
@@ -130,7 +130,7 @@ Example:
130130

131131
```js
132132
const $route = { path: 'http://www.example-path.com' }
133-
const wrapper = shallow(Component, {
133+
const wrapper = shallowMount(Component, {
134134
mocks: {
135135
$route
136136
}
@@ -206,7 +206,7 @@ When `sync` is `false`, the Vue component is rendered asynchronously.
206206

207207
## Other options
208208

209-
When the options for `mount` and `shallow` contain the options other than the mounting options, the component options are overwritten with those using [extends](https://vuejs.org/v2/api/#extends).
209+
When the options for `mount` and `shallowMount` contain the options other than the mounting options, the component options are overwritten with those using [extends](https://vuejs.org/v2/api/#extends).
210210

211211
```js
212212
const Component = {

docs/en/api/selectors.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ export default {
3232
```
3333

3434
```js
35-
import { shallow } from '@vue/test-utils'
35+
import { shallowMount } from '@vue/test-utils'
3636
import Foo from './Foo.vue'
3737

38-
const wrapper = shallow(Foo)
38+
const wrapper = shallowMount(Foo)
3939
expect(wrapper.is(Foo)).toBe(true)
4040
```
4141

docs/en/api/shallow.md renamed to docs/en/api/shallowMount.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# `shallow(component [, options])`
1+
# `shallowMount(component [, options])`
22

33
- **Arguments:**
44

@@ -27,12 +27,12 @@ Like [`mount`](mount.md), it creates a [`Wrapper`](wrapper/README.md) that conta
2727
**Without options:**
2828

2929
```js
30-
import { shallow } from '@vue/test-utils'
30+
import { shallowMount } from '@vue/test-utils'
3131
import Foo from './Foo.vue'
3232

3333
describe('Foo', () => {
3434
it('renders a div', () => {
35-
const wrapper = shallow(Foo)
35+
const wrapper = shallowMount(Foo)
3636
expect(wrapper.contains('div')).toBe(true)
3737
})
3838
})
@@ -41,12 +41,12 @@ describe('Foo', () => {
4141
**With Vue options:**
4242

4343
```js
44-
import { shallow } from '@vue/test-utils'
44+
import { shallowMount } from '@vue/test-utils'
4545
import Foo from './Foo.vue'
4646

4747
describe('Foo', () => {
4848
it('renders a div', () => {
49-
const wrapper = shallow(Foo, {
49+
const wrapper = shallowMount(Foo, {
5050
propsData: {
5151
color: 'red'
5252
}
@@ -59,12 +59,12 @@ describe('Foo', () => {
5959
**Attach to DOM:**
6060

6161
```js
62-
import { shallow } from '@vue/test-utils'
62+
import { shallowMount } from '@vue/test-utils'
6363
import Foo from './Foo.vue'
6464

6565
describe('Foo', () => {
6666
it('renders a div', () => {
67-
const wrapper = shallow(Foo, {
67+
const wrapper = shallowMount(Foo, {
6868
attachToDocument: true
6969
})
7070
expect(wrapper.contains('div')).toBe(true)
@@ -75,14 +75,14 @@ describe('Foo', () => {
7575
**Default and named slots:**
7676

7777
```js
78-
import { shallow } from '@vue/test-utils'
78+
import { shallowMount } from '@vue/test-utils'
7979
import Foo from './Foo.vue'
8080
import Bar from './Bar.vue'
8181
import FooBar from './FooBar.vue'
8282

8383
describe('Foo', () => {
8484
it('renders a div', () => {
85-
const wrapper = shallow(Foo, {
85+
const wrapper = shallowMount(Foo, {
8686
slots: {
8787
default: [Bar, FooBar],
8888
fooBar: FooBar, // Will match <slot name="FooBar" />,
@@ -97,13 +97,13 @@ describe('Foo', () => {
9797
**Stubbing global properties:**
9898

9999
```js
100-
import { shallow } from '@vue/test-utils'
100+
import { shallowMount } from '@vue/test-utils'
101101
import Foo from './Foo.vue'
102102

103103
describe('Foo', () => {
104104
it('renders a div', () => {
105105
const $route = { path: 'http://www.example-path.com' }
106-
const wrapper = shallow(Foo, {
106+
const wrapper = shallowMount(Foo, {
107107
mocks: {
108108
$route
109109
}

docs/en/api/wrapper-array/at.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ Returns `Wrapper` at `index` passed. Uses zero based numbering (i.e. first item
1010
- **Example:**
1111

1212
```js
13-
import { shallow } from '@vue/test-utils'
13+
import { shallowMount } from '@vue/test-utils'
1414
import Foo from './Foo.vue'
1515

16-
const wrapper = shallow(Foo)
16+
const wrapper = shallowMount(Foo)
1717
const divArray = wrapper.findAll('div')
1818
const secondDiv = divArray.at(1)
1919
expect(secondDiv.is('p')).toBe(true)

docs/en/api/wrapper-array/contains.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ Use any valid [selector](../selectors.md).
1212
- **Example:**
1313

1414
```js
15-
import { shallow } from '@vue/test-utils'
15+
import { shallowMount } from '@vue/test-utils'
1616
import Foo from './Foo.vue'
1717
import Bar from './Bar.vue'
1818

19-
const wrapper = shallow(Foo)
19+
const wrapper = shallowMount(Foo)
2020
const divArray = wrapper.findAll('div')
2121
expect(divArray.contains('p')).toBe(true)
2222
expect(divArray.contains(Bar)).toBe(true)

docs/en/api/wrapper-array/filter.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ A new `WrapperArray` instance containing `Wrapper` instances that returns true f
1414
- **Example:**
1515

1616
```js
17-
import { shallow } from '@vue/test-utils'
17+
import { shallowMount } from '@vue/test-utils'
1818
import Foo from './Foo.vue'
1919

20-
const wrapper = shallow(Foo)
20+
const wrapper = shallowMount(Foo)
2121
const filteredDivArray = wrapper.findAll('div').filter(w => !w.hasClass('filtered'))
2222
```

docs/en/api/wrapper/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ A `Wrapper` is an object that contains a mounted component or vnode and methods
88

99
`vm` `Component`: this is the `Vue` instance. You can access all the [instance methods and properties of a vm](https://vuejs.org/v2/api/#Instance-Properties) with `wrapper.vm`. This only exists on Vue component wrappers
1010
`element` `HTMLElement`: the root DOM node of the wrapper
11-
`options` `Object`: Object containing Vue Test Utils options passed to `mount` or `shallow`
12-
`options.attachedToDom` `Boolean`: True if `attachToDom` was passed to `mount` or `shallow`
11+
`options` `Object`: Object containing Vue Test Utils options passed to `mount` or `shallowMount`
12+
`options.attachedToDom` `Boolean`: True if `attachToDom` was passed to `mount` or `shallowMount`
1313

1414
- **Methods:**
1515

docs/en/guides/common-tips.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ In unit tests, we typically want to focus on the component being tested as an is
1818

1919
In addition, for components that contain many child components, the entire rendered tree can get really big. Repeatedly rendering all child components could slow down our tests.
2020

21-
Vue Test Utils allows you to mount a component without rendering its child components (by stubbing them) with the `shallow` method:
21+
Vue Test Utils allows you to mount a component without rendering its child components (by stubbing them) with the `shallowMount` method:
2222

2323
```js
24-
import { shallow } from '@vue/test-utils'
24+
import { shallowMount } from '@vue/test-utils'
2525

26-
const wrapper = shallow(Component) // returns a Wrapper containing a mounted Component instance
26+
const wrapper = shallowMount(Component) // returns a Wrapper containing a mounted Component instance
2727
wrapper.vm // the mounted Vue instance
2828
```
2929

docs/en/guides/testing-SFCs-with-karma.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ And create a test file named `test/Counter.spec.js` with the following code:
106106

107107
```js
108108
import { expect } from 'chai'
109-
import { shallow } from '@vue/test-utils'
109+
import { shallowMount } from '@vue/test-utils'
110110
import Counter from '../src/Counter.vue'
111111

112112
describe('Counter.vue', () => {
113113
it('increments count when button is clicked', () => {
114-
const wrapper = shallow(Counter)
114+
const wrapper = shallowMount(Counter)
115115
wrapper.find('button').trigger('click')
116116
expect(wrapper.find('div').text()).contains('1')
117117
})

docs/en/guides/testing-SFCs-with-mocha-webpack.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,12 @@ export default {
150150
And create a test file named `test/Counter.spec.js` with the following code:
151151

152152
```js
153-
import { shallow } from '@vue/test-utils'
153+
import { shallowMount } from '@vue/test-utils'
154154
import Counter from '../src/Counter.vue'
155155

156156
describe('Counter.vue', () => {
157157
it('increments count when button is clicked', () => {
158-
const wrapper = shallow(Counter)
158+
const wrapper = shallowMount(Counter)
159159
wrapper.find('button').trigger('click')
160160
expect(wrapper.find('div').text()).toMatch('1')
161161
})

docs/en/guides/testing-async-components.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ The below component makes an API call when a button is clicked, then assigns the
4444
A test can be written like this:
4545

4646
``` js
47-
import { shallow } from '@vue/test-utils'
47+
import { shallowMount } from '@vue/test-utils'
4848
import Foo from './Foo'
4949
jest.mock('axios')
5050

5151
test('Foo', () => {
5252
it('fetches async when a button is clicked', () => {
53-
const wrapper = shallow(Foo)
53+
const wrapper = shallowMount(Foo)
5454
wrapper.find('button').trigger('click')
5555
expect(wrapper.vm.value).toBe('value')
5656
})
@@ -62,7 +62,7 @@ This test currently fails because the assertion is called before the promise in
6262
``` js
6363
test('Foo', () => {
6464
it('fetches async when a button is clicked', (done) => {
65-
const wrapper = shallow(Foo)
65+
const wrapper = shallowMount(Foo)
6666
wrapper.find('button').trigger('click')
6767
wrapper.vm.$nextTick(() => {
6868
expect(wrapper.vm.value).toBe('value')
@@ -79,14 +79,14 @@ Another solution is to use an `async` function and the npm package `flush-promis
7979
The updated test looks like this:
8080

8181
``` js
82-
import { shallow } from '@vue/test-utils'
82+
import { shallowMount } from '@vue/test-utils'
8383
import flushPromises from 'flush-promises'
8484
import Foo from './Foo'
8585
jest.mock('axios')
8686

8787
test('Foo', () => {
8888
it('fetches async when a button is clicked', async () => {
89-
const wrapper = shallow(Foo)
89+
const wrapper = shallowMount(Foo)
9090
wrapper.find('button').trigger('click')
9191
await flushPromises()
9292
expect(wrapper.vm.value).toBe('value')

docs/en/guides/using-with-vue-router.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ You should never install Vue Router on the Vue base constructor in tests. Instal
77
To avoid this, we can create a localVue, and install Vue Router on that.
88

99
```js
10-
import { shallow, createLocalVue } from '@vue/test-utils'
10+
import { shallowMount, createLocalVue } from '@vue/test-utils'
1111
import VueRouter from 'vue-router'
1212

1313
const localVue = createLocalVue()
1414
localVue.use(VueRouter)
1515
const router = new VueRouter()
1616

17-
shallow(Component, {
17+
shallowMount(Component, {
1818
localVue,
1919
router
2020
})
@@ -31,23 +31,23 @@ When we run tests, we need to make these Vue Router components available to the
3131
### Using stubs
3232

3333
```js
34-
import { shallow } from '@vue/test-utils'
34+
import { shallowMount } from '@vue/test-utils'
3535

36-
shallow(Component, {
36+
shallowMount(Component, {
3737
stubs: ['router-link', 'router-view']
3838
})
3939
```
4040

4141
### Installing Vue Router with localVue
4242

4343
```js
44-
import { shallow, createLocalVue } from '@vue/test-utils'
44+
import { shallowMount, createLocalVue } from '@vue/test-utils'
4545
import VueRouter from 'vue-router'
4646

4747
const localVue = createLocalVue()
4848
localVue.use(VueRouter)
4949

50-
shallow(Component, {
50+
shallowMount(Component, {
5151
localVue
5252
})
5353
```
@@ -57,13 +57,13 @@ shallow(Component, {
5757
Sometimes you want to test that a component does something with parameters from the `$route` and `$router` objects. To do that, you can pass custom mocks to the Vue instance.
5858

5959
```js
60-
import { shallow } from '@vue/test-utils'
60+
import { shallowMount } from '@vue/test-utils'
6161

6262
const $route = {
6363
path: '/some/path'
6464
}
6565

66-
const wrapper = shallow(Component, {
66+
const wrapper = shallowMount(Component, {
6767
mocks: {
6868
$route
6969
}

0 commit comments

Comments
 (0)