Select the types of activity you want to include in your feed.
[READ-ONLY] Mirror of https://github.com/danielroe/nuxt-vitest. An vitest environment with support for testing code that needs a Nuxt runtime environment
···105105// your tests here
106106```
107107108108+109109+### `mockComponent`
110110+111111+`mockComponent` allows you to mock Nuxt's component.
112112+The first argument can be the component name in PascalCase, or the relative path of the component.
113113+The second argument can is a factory function that returns the mocked component.
114114+115115+For example, to mock `MyComponent`, you can:
116116+117117+```ts
118118+import { mockComponent } from 'nuxt-vitest/utils'
119119+120120+mockComponent('MyComponent', {
121121+ props: {
122122+ value: String
123123+ },
124124+ setup(props) {
125125+ // ...
126126+ }
127127+})
128128+129129+// relative path or alias also works
130130+mockComponent('~/components/my-component.vue', async () => {
131131+ // or a factory function
132132+ return {
133133+ setup(props) {
134134+ // ...
135135+ }
136136+ }
137137+})
138138+139139+// or you can use SFC for redirecting to a mock component
140140+mockComponent('MyComponent', () => import('./MockComponent.vue'))
141141+142142+// your tests here
143143+```
144144+145145+> **Note**: You can't reference to local variables in the factory function since they are hoisted. If you need to access Vue APIs or other variables, you need to import them in your factory function.
146146+147147+```ts
148148+mockComponent('MyComponent', async () => {
149149+ const { ref, h } = await import('vue')
150150+151151+ return {
152152+ setup(props) {
153153+ const counter = ref(0)
154154+ return () => h('div', null, counter.value)
155155+ }
156156+ }
157157+})
158158+```
159159+108160## 💻 Development
109161110162- Clone this repository