Skip to content

Commit

Permalink
Merge pull request #10835 from qmonmert/vueroutertest
Browse files Browse the repository at this point in the history
Vue: add tests for HomeRouter
  • Loading branch information
pascalgrimaud committed Sep 14, 2024
2 parents b825bb2 + e5bd122 commit 42bf32c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public JHipsterModule buildVueModule(JHipsterModuleProperties properties) {
.add(SOURCE.template("Dummy.spec.ts"), to("src/test/webapp/unit/Dummy.spec.ts"))
.add(APP_SOURCE.template("test/webapp/unit/shared/http/infrastructure/secondary/AxiosHttp.spec.ts.mustache"), TEST_DESTINATION.append("unit/shared/http/infrastructure/secondary/AxiosHttp.spec.ts"))
.add(APP_SOURCE.template("test/webapp/unit/shared/http/infrastructure/secondary/AxiosStub.ts.mustache"), TEST_DESTINATION.append("unit/shared/http/infrastructure/secondary/AxiosStub.ts"))
.add(APP_SOURCE.template("test/webapp/unit/router/HomeRouter.spec.ts.mustache"), TEST_DESTINATION.append("unit/router/HomeRouter.spec.ts"))
.and()
.build();
//@formatter:on
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createRouter, createWebHistory } from 'vue-router';
import { homeRoutes } from '@/home/application/HomeRouter';

const routes = [...homeRoutes()];
export const routes = [...homeRoutes()];

const router = createRouter({
history: createWebHistory(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { mount, VueWrapper } from '@vue/test-utils';
import { beforeEach, describe, expect, it } from 'vitest';
import { createRouter, createWebHistory, Router } from 'vue-router';
import { routes } from '@/router';
import HomepageVue from '@/home/infrastructure/primary/HomepageVue.vue';

let router: Router;
beforeEach(async () => {
router = createRouter({
history: createWebHistory(),
routes,
});
});

const wrap = (): VueWrapper => {
return mount(HomepageVue, {
global: {
plugins: [router],
},
});
};

describe('Router', () => {
describe('Navigation on HomepageVue', () => {
it('should navigate on HomepageVue when the URL is /', async () => {
router.push('/');
await router.isReady();
const wrapper = wrap();
expect(wrapper.html()).toContain('Vue 3 + TypeScript + Vite');
});

it('should navigate on HomepageVue when the URL is /home', async () => {
router.push('/home');
await router.isReady();
const wrapper = wrap();
expect(wrapper.html()).toContain('Vue 3 + TypeScript + Vite');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ void shouldCreateVueModule() {
.hasPrefixedFiles("src/main/webapp/content/images", "JHipster-Lite-neon-green.png", "VueLogo.png")
.hasFiles("src/test/webapp/unit/Dummy.spec.ts")
.hasFiles("src/test/webapp/unit/shared/http/infrastructure/secondary/AxiosHttp.spec.ts")
.hasFiles("src/test/webapp/unit/shared/http/infrastructure/secondary/AxiosStub.ts");
.hasFiles("src/test/webapp/unit/shared/http/infrastructure/secondary/AxiosStub.ts")
.hasFiles("src/test/webapp/unit/router/HomeRouter.spec.ts");
//@formatter:on
}

Expand Down

0 comments on commit 42bf32c

Please sign in to comment.