Skip to content

Commit 048f665

Browse files
Add composition api docs (#183)
* add more context for call in computed properties * Apply suggestions from code review * Just updating a spelling mistake * Demo app vue 3 - Parent visible (#181) * add more context for call in computed properties * fix(test): Test for parent visibility using isVisible Co-authored-by: Lachlan Miller <[email protected]> * add more context for call in computed properties * Add more context in computed properties (#179) * add more context for call in computed properties * Apply suggestions from code review Co-authored-by: Lachlan Miller <[email protected]> * feat(docs): Add composition api * feat(doc): Minor touches for docs * feat(docs): Rework text for composition api * Update setting-up-for-tdd.md Co-authored-by: Lachlan Miller <[email protected]>
1 parent 1208f0c commit 048f665

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/v3/setting-up-for-tdd.md

+29
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,33 @@ Greeting.vue
207207

208208
Jest gives us good feedback. We can see the expected and actual result, as well as on which line the expectation failed. The test did fail, as expected. Revert `Greeting.vue` and make sure the test is passing again.
209209

210+
## Using Vue 3 and the Composition API
211+
212+
Vue 3 adds another API for building components - the Composition API. One sign of a good test is we avoid testing implementation details (how the code works) but instead focus on behavior (what the code does). Let's refactor the above component and see what happens. If the test still passes, we know it's testing the right things. If it fails, we could be testing an implementation detail
213+
214+
```ts
215+
<template>
216+
<div>
217+
{{ greeting }}
218+
</div>
219+
</template>
220+
221+
<script lang="ts">
222+
export default {
223+
name: 'Greeting',
224+
setup() {
225+
const greeting = 'Vue and TDD';
226+
227+
return {
228+
greeting,
229+
};
230+
},
231+
};
232+
</script>
233+
```
234+
235+
When starting with the Composition API you often forget to add the variable to the return. Try omitting this and see how the test fails. If you are planning to convert some of your Options API components the Composition API, some tests can give you confidence and provide a positive feedback loop during the refactor.
236+
237+
## Next
238+
210239
Next we will look at the two methods `vue-test-utils` provides to render components: `mount` and `shallowMount`.

0 commit comments

Comments
 (0)