Testing Components
Components are at the core of Vue.js applications. Writing unit tests for them is straightforward with vue-test-utils
and Jest. Having tests that exercise the majority of your components gives you confidence that they behave as designed. Ideal unit tests for components run quickly and are simple.
We'll carry on building the blog application example. We have now built the heading, but a blog usually also needs a list of posts to display.
We'll create a PostList
component. For now, it will just render a div
wrapper and support a posts
Array
prop:
<template> Â Â <div class="flex flex-col w-full"> Â Â </div> </template> <script> export default { Â Â props: { Â Â Â Â posts: { Â Â Â Â Â Â type: Array, Â Â Â Â Â Â default: () => [] Â Â Â Â } Â Â } } </script>
We can add some data in the App...