Skip to content

Commit 19de5da

Browse files
authored
Merge pull request #11 from vuejs/set-props
Add API reference for setProps
2 parents ab9b961 + 26cd97a commit 19de5da

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/api/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,42 @@ test('emitted', () => {
619619
})
620620
```
621621

622+
### `setProps`
623+
624+
Updates component props.
625+
626+
`setProps` returns `Vue.nextTick`, so you will have to call it with `await` to ensure the DOM has been updated before making an assertion.
627+
628+
`Component.vue`:
629+
630+
```vue
631+
<template>
632+
<div>{{ message }}</div>
633+
</template>
634+
635+
<script>
636+
export default {
637+
props: ['message'],
638+
}
639+
</script>
640+
```
641+
642+
`Component.spec.js`
643+
644+
```js
645+
test('updates prop', async () => {
646+
const wrapper = mount(Component, {
647+
props: {
648+
message: 'hello'
649+
}
650+
})
651+
expect(wrapper.html()).toContain('hello')
652+
653+
await wrapper.setProps({ message: 'goodbye' })
654+
expect(wrapper.html()).toContain('goodbye')
655+
})
656+
```
657+
622658
### `setValue`
623659

624660
Sets a value on DOM element, including:

0 commit comments

Comments
 (0)