Skip to content

Commit

Permalink
test: remove test helper createMockActionComposables
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JammingBen committed Sep 27, 2023
1 parent 44c1c71 commit 9de1bb6
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
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'
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<string, any> = {}
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')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
createMockActionComposables,
createStore,
defaultComponentMocks,
defaultPlugins,
Expand All @@ -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<string, any> = {}
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'))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
createMockActionComposables,
createStore,
defaultComponentMocks,
defaultPlugins,
Expand All @@ -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<string, any> = {}
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'))
)
Expand Down
10 changes: 9 additions & 1 deletion packages/web-app-admin-settings/tests/unit/views/Spaces.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ import { Graph } from 'web-client'
import { mockDeep } from 'jest-mock-extended'
import { ClientService } from 'web-pkg/src'
import {
createMockActionComposables,
createStore,
defaultComponentMocks,
defaultPlugins,
defaultStoreMockOptions,
mount
} from 'web-test-helpers'
import Spaces from '../../../src/views/Spaces.vue'
import { ref } from 'vue'

function createMockActionComposables(module) {
const mockModule: Record<string, any> = {}
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'))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
createMockActionComposables,
createStore,
defaultComponentMocks,
defaultPlugins,
Expand All @@ -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<string, any> = {}
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'))
)
Expand Down
10 changes: 1 addition & 9 deletions packages/web-test-helpers/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -57,11 +57,3 @@ export const createRouter = (options?: Partial<RouterOptions>) =>
strict: false,
...options
})

export const createMockActionComposables = (module) => {
const mockModule: Record<string, any> = {}
for (const m of Object.keys(module)) {
mockModule[m] = jest.fn(() => ({ actions: ref([]) }))
}
return mockModule
}

0 comments on commit 9de1bb6

Please sign in to comment.