File tree Expand file tree Collapse file tree 1 file changed +34
-6
lines changed Expand file tree Collapse file tree 1 file changed +34
-6
lines changed Original file line number Diff line number Diff line change 1
1
# setProps(props)
2
2
3
- Sets ` Wrapper ` ` vm ` props and forces update.
4
-
5
- ** Note the Wrapper must contain a Vue instance.**
6
-
7
3
- ** Arguments:**
8
4
- ` {Object} props `
9
5
10
- - ** Example:**
6
+ - ** Usage:**
7
+
8
+ Sets ` Wrapper ` ` vm ` props and forces update.
9
+
10
+ ** Note the Wrapper must contain a Vue instance.**
11
11
12
12
``` js
13
13
import { mount } from ' vue-test-utils'
@@ -16,5 +16,33 @@ import Foo from './Foo.vue'
16
16
17
17
const wrapper = mount (Foo)
18
18
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' )
20
48
```
You can’t perform that action at this time.
0 commit comments