From 9de1bb659eb532dff0a1a721f6178e3c449bbbef Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Wed, 27 Sep 2023 10:11:33 +0200 Subject: [PATCH] test: remove test helper createMockActionComposables Importing and using this helper with jest.mock() can cause problems when the mocked method is exported via a index.ts file, hence removing it. --- .../components/Groups/ContextActions.spec.ts | 17 ++++++++++------- .../components/Spaces/ContextActions.spec.ts | 11 +++++++++-- .../Spaces/SideBar/ActionsPanel.spec.ts | 11 +++++++++-- .../tests/unit/views/Spaces.spec.ts | 10 +++++++++- .../components/FilesList/ContextActions.spec.ts | 11 +++++++++-- packages/web-test-helpers/src/helpers.ts | 10 +--------- 6 files changed, 47 insertions(+), 23 deletions(-) diff --git a/packages/web-app-admin-settings/tests/unit/components/Groups/ContextActions.spec.ts b/packages/web-app-admin-settings/tests/unit/components/Groups/ContextActions.spec.ts index 948ed35c06d..c6fb7c17494 100644 --- a/packages/web-app-admin-settings/tests/unit/components/Groups/ContextActions.spec.ts +++ b/packages/web-app-admin-settings/tests/unit/components/Groups/ContextActions.spec.ts @@ -1,9 +1,4 @@ -import { - createMockActionComposables, - defaultPlugins, - defaultStoreMockOptions, - mount -} from 'web-test-helpers' +import { defaultPlugins, defaultStoreMockOptions, mount } from 'web-test-helpers' import { mock } from 'jest-mock-extended' import { Resource } from 'web-client/src/helpers' import ContextActions from '../../../../src/components/Groups/ContextActions.vue' @@ -11,9 +6,17 @@ import { useGroupActionsDelete, useGroupActionsEdit } from 'web-app-admin-settings/src/composables/actions' -import { computed } from 'vue' +import { computed, ref } from 'vue' import { Action } from 'web-pkg/src/composables/actions' +function createMockActionComposables(module) { + const mockModule: Record = {} + for (const m of Object.keys(module)) { + mockModule[m] = jest.fn(() => ({ actions: ref([]) })) + } + return mockModule +} + jest.mock('web-pkg/src/composables/actions/useActionsShowDetails', () => createMockActionComposables( jest.requireActual('web-pkg/src/composables/actions/useActionsShowDetails') diff --git a/packages/web-app-admin-settings/tests/unit/components/Spaces/ContextActions.spec.ts b/packages/web-app-admin-settings/tests/unit/components/Spaces/ContextActions.spec.ts index b6d10529abe..1536da04bcc 100644 --- a/packages/web-app-admin-settings/tests/unit/components/Spaces/ContextActions.spec.ts +++ b/packages/web-app-admin-settings/tests/unit/components/Spaces/ContextActions.spec.ts @@ -1,5 +1,4 @@ import { - createMockActionComposables, createStore, defaultComponentMocks, defaultPlugins, @@ -17,7 +16,15 @@ import { useSpaceActionsEditQuota, useSpaceActionsRename } from 'web-pkg/src/composables/actions' -import { computed } from 'vue' +import { computed, ref } from 'vue' + +function createMockActionComposables(module) { + const mockModule: Record = {} + for (const m of Object.keys(module)) { + mockModule[m] = jest.fn(() => ({ actions: ref([]) })) + } + return mockModule +} jest.mock('web-pkg/src/composables/actions/spaces', () => createMockActionComposables(jest.requireActual('web-pkg/src/composables/actions/spaces')) diff --git a/packages/web-app-admin-settings/tests/unit/components/Spaces/SideBar/ActionsPanel.spec.ts b/packages/web-app-admin-settings/tests/unit/components/Spaces/SideBar/ActionsPanel.spec.ts index 54f9d405a60..af9cc69773f 100644 --- a/packages/web-app-admin-settings/tests/unit/components/Spaces/SideBar/ActionsPanel.spec.ts +++ b/packages/web-app-admin-settings/tests/unit/components/Spaces/SideBar/ActionsPanel.spec.ts @@ -1,5 +1,4 @@ import { - createMockActionComposables, createStore, defaultComponentMocks, defaultPlugins, @@ -16,9 +15,17 @@ import { useSpaceActionsEditQuota, useSpaceActionsRename } from 'web-pkg/src/composables/actions/spaces' -import { computed } from 'vue' +import { computed, ref } from 'vue' import { Action } from 'web-pkg/src/composables/actions' +function createMockActionComposables(module) { + const mockModule: Record = {} + for (const m of Object.keys(module)) { + mockModule[m] = jest.fn(() => ({ actions: ref([]) })) + } + return mockModule +} + jest.mock('web-pkg/src/composables/actions/spaces', () => createMockActionComposables(jest.requireActual('web-pkg/src/composables/actions/spaces')) ) diff --git a/packages/web-app-admin-settings/tests/unit/views/Spaces.spec.ts b/packages/web-app-admin-settings/tests/unit/views/Spaces.spec.ts index e6ceef5ac9e..77af9d4ad9f 100644 --- a/packages/web-app-admin-settings/tests/unit/views/Spaces.spec.ts +++ b/packages/web-app-admin-settings/tests/unit/views/Spaces.spec.ts @@ -3,7 +3,6 @@ import { Graph } from 'web-client' import { mockDeep } from 'jest-mock-extended' import { ClientService } from 'web-pkg/src' import { - createMockActionComposables, createStore, defaultComponentMocks, defaultPlugins, @@ -11,6 +10,15 @@ import { mount } from 'web-test-helpers' import Spaces from '../../../src/views/Spaces.vue' +import { ref } from 'vue' + +function createMockActionComposables(module) { + const mockModule: Record = {} + for (const m of Object.keys(module)) { + mockModule[m] = jest.fn(() => ({ actions: ref([]) })) + } + return mockModule +} jest.mock('web-pkg/src/composables/actions/spaces', () => createMockActionComposables(jest.requireActual('web-pkg/src/composables/actions/spaces')) diff --git a/packages/web-pkg/tests/unit/components/FilesList/ContextActions.spec.ts b/packages/web-pkg/tests/unit/components/FilesList/ContextActions.spec.ts index 949a523a583..c6020641234 100644 --- a/packages/web-pkg/tests/unit/components/FilesList/ContextActions.spec.ts +++ b/packages/web-pkg/tests/unit/components/FilesList/ContextActions.spec.ts @@ -1,5 +1,4 @@ import { - createMockActionComposables, createStore, defaultComponentMocks, defaultPlugins, @@ -17,9 +16,17 @@ import { useFileActionsRename, useFileActionsCopy } from 'web-pkg/src/composables/actions/files' -import { computed } from 'vue' +import { computed, ref } from 'vue' import { Action } from 'web-pkg/src/composables/actions' +function createMockActionComposables(module) { + const mockModule: Record = {} + for (const m of Object.keys(module)) { + mockModule[m] = jest.fn(() => ({ actions: ref([]) })) + } + return mockModule +} + jest.mock('web-pkg/src/composables/actions/files', () => createMockActionComposables(jest.requireActual('web-pkg/src/composables/actions/files')) ) diff --git a/packages/web-test-helpers/src/helpers.ts b/packages/web-test-helpers/src/helpers.ts index 367fb9842ca..d4c5043c31c 100644 --- a/packages/web-test-helpers/src/helpers.ts +++ b/packages/web-test-helpers/src/helpers.ts @@ -1,6 +1,6 @@ import { createStore as _createStore, StoreOptions } from 'vuex' import { mount } from '@vue/test-utils' -import { defineComponent, ref } from 'vue' +import { defineComponent } from 'vue' import { defaultPlugins, DefaultPluginsOptions } from 'web-test-helpers' import { createRouter as _createRouter } from 'web-runtime/src/router' import { createMemoryHistory, RouterOptions } from 'vue-router' @@ -57,11 +57,3 @@ export const createRouter = (options?: Partial) => strict: false, ...options }) - -export const createMockActionComposables = (module) => { - const mockModule: Record = {} - for (const m of Object.keys(module)) { - mockModule[m] = jest.fn(() => ({ actions: ref([]) })) - } - return mockModule -}