fix(vue): ootb unit testing should work with --routing #19921 (#23441)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

## Current Behavior
<!-- This is the behavior we have today -->
When generating a vue application with routing and testing, the test
setup is incorrect and fails


## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
The test setup for vue applications with routing should work OOTB

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #19921
This commit is contained in:
Colum Ferry 2024-05-16 16:38:16 +01:00 committed by GitHub
parent e9bf1a2acb
commit 381e5cd494
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 4 deletions

View File

@ -121,8 +121,9 @@ import { mount } from '@vue/test-utils';
import App from './App.vue'; import App from './App.vue';
describe('App', () => { describe('App', () => {
it('renders properly', () => { it('renders properly', async () => {
const wrapper = mount(App, {}); const wrapper = mount(App, {});
expect(wrapper.text()).toContain('Welcome test 👋'); expect(wrapper.text()).toContain('Welcome test 👋');
}); });
}); });

View File

@ -1,12 +1,17 @@
<% if ( unitTestRunner === 'vitest' ) { %> <% if ( unitTestRunner === 'vitest' ) { %>
import { describe, it, expect } from 'vitest' import { describe, it, expect } from 'vitest'
<% } %><% if( routing ) { %>
import router from '../router';
<% } %> <% } %>
import { mount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import App from './App.vue'; import App from './App.vue';
describe('App', () => { describe('App', () => {
it('renders properly', () => { it('renders properly', async () => {
const wrapper = mount(App, {}) const wrapper = mount(App, <% if( routing ) { %>{ global: { plugins: [router] }}<% } else { %>{}<% } %>)
<% if( routing ) { %>
await router.isReady();
<% } %>
expect(wrapper.text()).toContain('Welcome <%= title %> 👋') expect(wrapper.text()).toContain('Welcome <%= title %> 👋')
}) })
}); });

View File

@ -4,6 +4,6 @@ import NxWelcome from '../app/NxWelcome.vue'
<template> <template>
<main> <main>
<NxWelcome /> <NxWelcome title="<%= title %>" />
</main> </main>
</template> </template>