Skip to content

Commit 020fc4d

Browse files
lmiller1990eddyerburgh
authored andcommitted
docs: fix example and add example using setProps (#102)
* Fix example and add example using setProps * Remove unnecessary sentence
1 parent 73b6bc9 commit 020fc4d

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

docs/en/api/wrapper/setProps.md

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# setProps(props)
22

3-
Sets `Wrapper` `vm` props and forces update.
4-
5-
**Note the Wrapper must contain a Vue instance.**
6-
73
- **Arguments:**
84
- `{Object} props`
95

10-
- **Example:**
6+
- **Usage:**
7+
8+
Sets `Wrapper` `vm` props and forces update.
9+
10+
**Note the Wrapper must contain a Vue instance.**
1111

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

1717
const wrapper = mount(Foo)
1818
wrapper.setProps({ foo: 'bar' })
19-
expect(wrapper.props().foo).toBe('bar')
19+
expect(wrapper.vm.foo).to.equal('bar')
20+
```
21+
22+
You can also pass a `propsData` object, which will initialize the Vue instance with passed values.
23+
24+
``` js
25+
// Foo.vue
26+
export default {
27+
props: {
28+
foo: {
29+
type: String,
30+
required: true
31+
}
32+
}
33+
}
34+
```
35+
36+
``` js
37+
import { mount } from 'vue-test-utils'
38+
import { expect } from 'chai'
39+
import Foo from './Foo.vue'
40+
41+
const wrapper = mount(Foo, {
42+
propsData: {
43+
foo: 'bar'
44+
}
45+
})
46+
47+
expect(wrapper.vm.foo).to.equal('bar')
2048
```

0 commit comments

Comments
 (0)