Skip to content

shallow -> shallowMount #1623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/v2/cookbook/unit-testing-vue-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ export default {
```

```js
import { shallow } from '@vue/test-utils'
import { shallowMount } from '@vue/test-utils'

test('Foo', () => {
// render the component
const wrapper = shallow(Hello)
const wrapper = shallowMount(Hello)

// should not allow for `username` less than 7 characters, excludes whitespace
wrapper.setData({ username: ' '.repeat(7) })
Expand Down Expand Up @@ -145,11 +145,11 @@ The things that we should test are:
And our first attempt at test:

```js
import { shallow } from '@vue/test-utils'
import { shallowMount } from '@vue/test-utils'

describe('Foo', () => {
it('renders a message and responds correctly to user input', () => {
const wrapper = shallow(Foo, {
const wrapper = shallowMount(Foo, {
data: {
message: 'Hello World',
username: ''
Expand Down Expand Up @@ -183,11 +183,11 @@ The below example improves the test by:

*Updated test*:
```js
import { shallow } from '@vue/test-utils'
import { shallowMount } from '@vue/test-utils'
import Foo from './Foo'

const factory = (values = {}) => {
return shallow(Foo, {
return shallowMount(Foo, {
data: { ...values }
})
}
Expand Down Expand Up @@ -221,7 +221,7 @@ describe('Foo', () => {

Points to note:

At the top, we declare the factory function which merges the `values` object into `data` and returns a new `wrapper` instance. This way, we don't need to duplicate `const wrapper = shallow(Foo)` in every test. Another great benefit to this is when more complex components with a method or computed property you might want to mock or stub in every test, you only need to declare it once.
At the top, we declare the factory function which merges the `values` object into `data` and returns a new `wrapper` instance. This way, we don't need to duplicate `const wrapper = shallowMount(Foo)` in every test. Another great benefit to this is when more complex components with a method or computed property you might want to mock or stub in every test, you only need to declare it once.

## Additional Context

Expand Down