From 47e446baa2998e5c3013309faab22b37db31d2c6 Mon Sep 17 00:00:00 2001 From: Colum Ferry Date: Thu, 16 May 2024 16:03:56 +0100 Subject: [PATCH] fix(vue): ootb unit testing should work with --routing #19921 --- .../application/__snapshots__/application.spec.ts.snap | 3 ++- .../files/common/src/app/App.spec.ts.template | 9 +++++++-- .../files/routing/src/views/HomeView.vue.template | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/vue/src/generators/application/__snapshots__/application.spec.ts.snap b/packages/vue/src/generators/application/__snapshots__/application.spec.ts.snap index 78d7d6ae315ac..789f80bc7f3a7 100644 --- a/packages/vue/src/generators/application/__snapshots__/application.spec.ts.snap +++ b/packages/vue/src/generators/application/__snapshots__/application.spec.ts.snap @@ -121,8 +121,9 @@ import { mount } from '@vue/test-utils'; import App from './App.vue'; describe('App', () => { - it('renders properly', () => { + it('renders properly', async () => { const wrapper = mount(App, {}); + expect(wrapper.text()).toContain('Welcome test 👋'); }); }); diff --git a/packages/vue/src/generators/application/files/common/src/app/App.spec.ts.template b/packages/vue/src/generators/application/files/common/src/app/App.spec.ts.template index e146c1f6ef254..e8b016b534175 100644 --- a/packages/vue/src/generators/application/files/common/src/app/App.spec.ts.template +++ b/packages/vue/src/generators/application/files/common/src/app/App.spec.ts.template @@ -1,12 +1,17 @@ <% if ( unitTestRunner === 'vitest' ) { %> import { describe, it, expect } from 'vitest' +<% } %><% if( routing ) { %> +import router from '../router'; <% } %> import { mount } from '@vue/test-utils' import App from './App.vue'; describe('App', () => { - it('renders properly', () => { - const wrapper = mount(App, {}) + it('renders properly', async () => { + const wrapper = mount(App, <% if( routing ) { %>{ global: { plugins: [router] }}<% } else { %>{}<% } %>) + <% if( routing ) { %> + await router.isReady(); + <% } %> expect(wrapper.text()).toContain('Welcome <%= title %> 👋') }) }); diff --git a/packages/vue/src/generators/application/files/routing/src/views/HomeView.vue.template b/packages/vue/src/generators/application/files/routing/src/views/HomeView.vue.template index 07cab06db9077..9f9f06545e1ea 100644 --- a/packages/vue/src/generators/application/files/routing/src/views/HomeView.vue.template +++ b/packages/vue/src/generators/application/files/routing/src/views/HomeView.vue.template @@ -4,6 +4,6 @@ import NxWelcome from '../app/NxWelcome.vue'