From 2a1a80d296c19e4aef87905519a873f31a6075b9 Mon Sep 17 00:00:00 2001 From: lachlan Date: Sun, 15 Oct 2017 21:22:47 +0900 Subject: [PATCH 1/2] Fix example and add example using setProps --- docs/en/api/wrapper/setProps.md | 40 ++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/docs/en/api/wrapper/setProps.md b/docs/en/api/wrapper/setProps.md index 67ff3f3b1..3d4754014 100644 --- a/docs/en/api/wrapper/setProps.md +++ b/docs/en/api/wrapper/setProps.md @@ -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' @@ -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`. + +``` 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') ``` From 6f455050cecc5e2ccafe316c8fefdf5bccf62d7e Mon Sep 17 00:00:00 2001 From: lachlan Date: Mon, 16 Oct 2017 10:26:48 +0900 Subject: [PATCH 2/2] Remove unnecessary sentence --- docs/en/api/wrapper/setProps.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/api/wrapper/setProps.md b/docs/en/api/wrapper/setProps.md index 3d4754014..7a55124c4 100644 --- a/docs/en/api/wrapper/setProps.md +++ b/docs/en/api/wrapper/setProps.md @@ -19,7 +19,7 @@ wrapper.setProps({ foo: '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`. +You can also pass a `propsData` object, which will initialize the Vue instance with passed values. ``` js // Foo.vue