diff --git a/packages/blocks/test/nuxt/index.test.js b/packages/blocks/test/nuxt/index.test.js index c4d8e37a7..680c42216 100644 --- a/packages/blocks/test/nuxt/index.test.js +++ b/packages/blocks/test/nuxt/index.test.js @@ -1,17 +1,18 @@ import DruxtBlocksNuxtModule from '../../src/nuxt' -// jest.mock('../src/nuxt/storybook') +jest.mock('../../src/nuxt/storybook') jest.mock('@nuxt/kit', () => ({ defineNuxtModule: (module) => module, installModule: jest.fn(), })) +import { installModule } from '@nuxt/kit' const nuxtMock = { hook: jest.fn((hook, fn) => { const arg = { 'components:dirs': [], - // 'storybook:config': { stories: [] } + 'storybook:config': { stories: [] } } return fn(arg[hook]) }), @@ -22,4 +23,7 @@ test('Nuxt module', async () => { druxt: {} } await DruxtBlocksNuxtModule.setup({}, nuxtMock) + + expect(installModule).toHaveBeenCalledTimes(1) + expect(nuxtMock.hook).toHaveBeenCalledTimes(2) }) diff --git a/packages/druxt/test/nuxt/index.test.js b/packages/druxt/test/nuxt/index.test.js index 3c320e8cd..12c47434d 100644 --- a/packages/druxt/test/nuxt/index.test.js +++ b/packages/druxt/test/nuxt/index.test.js @@ -43,6 +43,10 @@ describe('DruxtJS Nuxt module', () => { // Expect addPlugin to have been called with options. expect(addPluginTemplate).toHaveBeenCalledWith(expect.objectContaining({ options })) + + // Ensure that Druxt and Axios plugins are correctly ordered. + const mockPlugins = [{ src: `${nuxtMock.options.buildDir}/druxt.js` }, { src: `${nuxtMock.options.buildDir}/axios.js` }] + expect(nuxtMock.options.extendPlugins(mockPlugins)[0].src).toEqual(`${nuxtMock.options.buildDir}/axios.js`) }) test('Root options', async () => { diff --git a/packages/entity/test/nuxt/index.test.js b/packages/entity/test/nuxt/index.test.js index 686f39ecb..52d289ea0 100644 --- a/packages/entity/test/nuxt/index.test.js +++ b/packages/entity/test/nuxt/index.test.js @@ -1,11 +1,12 @@ import DruxtEntityNuxtModule from '../../src/nuxt' -// jest.mock('../src/nuxtStorybook') +jest.mock('../../src/nuxt/storybook') jest.mock('@nuxt/kit', () => ({ defineNuxtModule: (module) => module, installModule: jest.fn(), })) +import { installModule } from '@nuxt/kit' const nuxtMock = { hook: jest.fn((hook, fn) => { @@ -23,4 +24,7 @@ test('Nuxt module', async () => { modules: [], } await DruxtEntityNuxtModule.setup({}, nuxtMock) + + expect(installModule).toHaveBeenCalledTimes(2) + expect(nuxtMock.hook).toHaveBeenCalledTimes(2) }) diff --git a/packages/router/test/nuxt/index.test.js b/packages/router/test/nuxt/index.test.js index 9fe9802f9..d4d3c5025 100644 --- a/packages/router/test/nuxt/index.test.js +++ b/packages/router/test/nuxt/index.test.js @@ -20,7 +20,6 @@ const nuxtMock = { }), } - test('Nuxt module', async () => { nuxtMock.options = { build: {}, @@ -32,6 +31,8 @@ test('Nuxt module', async () => { nuxtMock.options.druxt.router = { pages: true } await DruxtRouterNuxtModule.setup({}, nuxtMock) + expect(installModule).toHaveBeenCalledTimes(1) + expect(extendPages).toHaveBeenCalledTimes(1) expect(addPluginTemplate).toHaveBeenCalledTimes(2) expect(addTemplate).toHaveBeenCalledTimes(2) expect(nuxtMock.hook).toHaveBeenCalledTimes(2)