Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(composables): add 100% coverage #1131

Merged
merged 19 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: composable tests - 100
  • Loading branch information
mdanilowicz committed Jul 23, 2024
commit a162a74fffc151acb18cf56e1a7b38f100386cf0
5 changes: 3 additions & 2 deletions packages/composables/src/_test/useSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type Injections = {
apiClient: {
invoke: ReturnType<typeof vi.fn>;
};
[key: string]: unknown;
patzick marked this conversation as resolved.
Show resolved Hide resolved
};

export function useSetup<V>(setup: () => V, customMocks?: Partial<Injections>) {
Expand All @@ -16,7 +17,7 @@ export function useSetup<V>(setup: () => V, customMocks?: Partial<Injections>) {
apiClient: { invoke: customMocks?.apiClient?.invoke ?? vi.fn() },
};

const compoment = defineComponent({
const component = defineComponent({
setup,
render() {
return h("div", []);
Expand All @@ -28,7 +29,7 @@ export function useSetup<V>(setup: () => V, customMocks?: Partial<Injections>) {
customMocks || {},
) as Injections;

const wrapper = shallowMount(compoment, {
const wrapper = shallowMount(component, {
global: {
provide: injections,
},
Expand Down
16 changes: 15 additions & 1 deletion packages/composables/src/useNotifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,22 @@ describe("useNotifications", () => {
});

it("injected empty swNotifications", () => {
const { vm } = useSetup(useNotifications);
const { vm } = useSetup(useNotifications, {
swNotifications: { value: null },
});

expect(vm.notifications).toEqual([]);
vm.removeOne(2332);
expect(vm.notifications).toEqual([]);
vm.pushSuccess("test");
});

it("injected empty swNotifications and push success", () => {
const { vm } = useSetup(useNotifications, {
swNotifications: { value: null },
});

vm.pushSuccess("test");
expect(vm.notifications.length).toBe(1);
});
});
2 changes: 1 addition & 1 deletion packages/composables/src/useNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function useNotifications(): UseNotificationsReturn {
const messageId = geterateId();
_notifications.value.push({
id: messageId,
type: options.type || "info",
type: options.type as NotificationType,
patzick marked this conversation as resolved.
Show resolved Hide resolved
message,
});
if (!persistent) {
Expand Down