diff --git a/examples/app-vitest-full/components/WrapperTests.vue b/examples/app-vitest-full/components/WrapperTests.vue index bcb2a08cb..54f6ea15f 100644 --- a/examples/app-vitest-full/components/WrapperTests.vue +++ b/examples/app-vitest-full/components/WrapperTests.vue @@ -8,6 +8,8 @@ function testExpose () { return 'expose was successful' } +const modelValue = defineModel({ default: false }) + defineExpose({ testExpose }) @@ -15,8 +17,15 @@ defineExpose({ diff --git a/examples/app-vitest-full/nuxt.config.ts b/examples/app-vitest-full/nuxt.config.ts index d3b9d4ee1..3999404d0 100644 --- a/examples/app-vitest-full/nuxt.config.ts +++ b/examples/app-vitest-full/nuxt.config.ts @@ -2,6 +2,13 @@ export default defineNuxtConfig({ devtools: { enabled: true }, modules: ['@nuxt/test-utils/module', '~/modules/custom'], + vite: { + vue: { + script: { + defineModel: true, + }, + }, + }, vitest: { startOnBoot: true, logToConsole: true, diff --git a/examples/app-vitest-full/tests/nuxt/index.spec.ts b/examples/app-vitest-full/tests/nuxt/index.spec.ts index 46acb463c..88e8ed412 100644 --- a/examples/app-vitest-full/tests/nuxt/index.spec.ts +++ b/examples/app-vitest-full/tests/nuxt/index.spec.ts @@ -10,6 +10,8 @@ import FetchComponent from '~/components/FetchComponent.vue' import OptionsComponent from '~/components/OptionsComponent.vue' import WrapperTests from '~/components/WrapperTests.vue' +import { mount } from '@vue/test-utils' + describe('client-side nuxt features', () => { it('can use core nuxt composables within test file', () => { expect(useAppConfig().hey).toMatchInlineSnapshot('false') @@ -100,7 +102,7 @@ describe('test utils', () => { it('can receive emitted events from components mounted within nuxt suspense', async () => { const component = await mountSuspended(WrapperTests) - component.find('button').trigger('click') + component.find('button#emitCustomEvent').trigger('click') expect(component.emitted()).toMatchInlineSnapshot(` { "customEvent": [ @@ -128,6 +130,20 @@ describe('test utils', () => { await server.close() }) + // This test works (you can delete it later) + it('can receive emitted events from components using defineModel', () => { + const component = mount(WrapperTests) + component.find('button#changeModelValue').trigger('click') + expect(component.emitted()).toHaveProperty('update:modelValue') + }) + + // TODO: fix this failing test + it.todo('can receive emitted events from components mounted within nuxt suspense using defineModel', async () => { + const component = await mountSuspended(WrapperTests) + component.find('button#changeModelValue').trigger('click') + expect(component.emitted()).toHaveProperty('update:modelValue') + }) + it('can mock fetch requests', async () => { registerEndpoint('https://jsonplaceholder.typicode.com/todos/1', () => ({ title: 'title from mocked api',