Skip to content

Commit 37f402f

Browse files
authored
Merge pull request #19 from codebryo/docs/replace-data-with-vm
Documentation: Replace references to data() with vm
2 parents cb05d9d + 81d6f73 commit 37f402f

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

docs/en/api/wrapper/setData.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ import Foo from './Foo.vue'
1616

1717
const wrapper = mount(Foo)
1818
wrapper.setData({ foo: 'bar' })
19-
expect(wrapper.data().foo).to.equal('bar')
20-
```
19+
expect(wrapper.vm.foo).to.equal('bar')
20+
```

docs/en/getting-started.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ That was easy as well, so let's step up the game.
9191

9292
### Component data
9393

94-
Changing the data of the component can be quite useful for efficient testing. The method `setData({...})` is ment for changing the data and `data()` returns the current data object of the component.
94+
Changing the data of the component can be quite useful for efficient testing. The method `setData({...})` is ment for changing the data on the instance. You can interact with the instance directly using the `vm` key. As Vue automatically sets all data values and computed properties as getters on the root instance, we can access those values straight away.
9595
It may be useful to change the data accordingly for a whole group of specs, so `beforeEach()` could be a good place for that:
9696

9797
```js
@@ -102,20 +102,12 @@ describe('Data interactions', () => {
102102
})
103103

104104
it('should be set to 10', () => {
105-
expect(wrapper.data().count).to.equal(10)
105+
expect(wrapper.vm.count).to.equal(10)
106106
})
107107
})
108108

109109
```
110110

111-
At this point you should also know that you can interact with the vue instance itself as well using the `vm` key.
112-
113-
```js
114-
wrapper.vm.$data
115-
// is equal to
116-
wrapper.data()
117-
```
118-
119111
### Interactions
120112

121113
This section will introduce two important methods of the wrapper object.
@@ -125,10 +117,10 @@ This section will introduce two important methods of the wrapper object.
125117

126118
describe('Trigger an event', () => {
127119
it('button should increment the count', () => {
128-
expect(wrapper.data().count).to.equal(0)
120+
expect(wrapper.vm.count).to.equal(0)
129121
const button = wrapper.find('button')
130122
button.trigger('click')
131-
expect(wrapper.data().count).to.equal(1)
123+
expect(wrapper.vm.count).to.equal(1)
132124
})
133125
})
134126

0 commit comments

Comments
 (0)