Skip to content

Commit f0fe484

Browse files
luizhf42gustavosbarreto
authored andcommitted
test(ui): simplify TagSelector tests and add flushPromises and unmount
1 parent 95f710e commit f0fe484

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

ui/tests/components/Tags/TagSelector.spec.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { flushPromises, mount, VueWrapper } from "@vue/test-utils";
22
import { createVuetify } from "vuetify";
33
import MockAdapter from "axios-mock-adapter";
4-
import { expect, describe, it, beforeEach } from "vitest";
4+
import { expect, describe, it, beforeEach, afterEach } from "vitest";
55
import { createPinia, setActivePinia } from "pinia";
66
import TagSelector from "@/components/Tags/TagSelector.vue";
77
import { router } from "@/router";
@@ -43,31 +43,22 @@ describe("Tag Selector", () => {
4343
});
4444
});
4545

46-
it("Is a Vue instance", () => {
47-
expect(wrapper.vm).toBeTruthy();
46+
afterEach(async () => {
47+
await flushPromises();
48+
wrapper.unmount();
4849
});
4950

5051
it("Renders the component", () => {
5152
expect(wrapper.html()).toMatchSnapshot();
5253
});
5354

54-
it("Data is defined", () => {
55-
expect(wrapper.vm.$data).toBeDefined();
56-
});
57-
5855
it("Renders components", () => {
5956
expect(wrapper.findComponent('[data-test="tags-btn"]').exists()).toBe(true);
6057
});
6158

6259
it("Successfully loads tags", async () => {
63-
mockTagsApi
64-
.onGet("http://localhost:3000/api/namespaces/fake-tenant-data/tags?filter=&page=1&per_page=10")
65-
.reply(200, tags);
66-
6760
await wrapper.findComponent('[data-test="tags-btn"]').trigger("click");
68-
6961
await flushPromises();
70-
7162
expect(wrapper.vm.fetchedTags).toEqual(tags);
7263
});
7364
});

0 commit comments

Comments
 (0)