Skip to content

Fix example and add example using setProps #102

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 2 commits into from
Oct 16, 2017
Merged
Changes from 1 commit
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
40 changes: 34 additions & 6 deletions docs/en/api/wrapper/setProps.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# setProps(props)

Sets `Wrapper` `vm` props and forces update.

**Note the Wrapper must contain a Vue instance.**

- **Arguments:**
- `{Object} props`

- **Example:**
- **Usage:**

Sets `Wrapper` `vm` props and forces update.

**Note the Wrapper must contain a Vue instance.**

```js
import { mount } from 'vue-test-utils'
Expand All @@ -16,5 +16,33 @@ import Foo from './Foo.vue'

const wrapper = mount(Foo)
wrapper.setProps({ foo: 'bar' })
expect(wrapper.props().foo).toBe('bar')
expect(wrapper.vm.foo).to.equal('bar')
```

You can also pass a `propsData` object, which will initialize the Vue instance with passed values. This is useful if you have a component or instance that has props which are `required`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove this section please"

This is useful if you have a component or instance that has props which are `required`.

I think the users will understand what it's useful for.


``` js
// Foo.vue
export default {
props: {
foo: {
type: String,
required: true
}
}
}
```

``` js
import { mount } from 'vue-test-utils'
import { expect } from 'chai'
import Foo from './Foo.vue'

const wrapper = mount(Foo, {
propsData: {
foo: 'bar'
}
})

expect(wrapper.vm.foo).to.equal('bar')
```