From 34ada4dc1bcbe8f6ff35151427dead45c7ba3f11 Mon Sep 17 00:00:00 2001 From: Stuart Clark Date: Thu, 19 Sep 2024 10:40:35 +1000 Subject: [PATCH] chore(#693): updated tests --- packages/entity/test/nuxt/index.test.js | 60 +++++++++++++++++++++---- 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/packages/entity/test/nuxt/index.test.js b/packages/entity/test/nuxt/index.test.js index 52d289ea..23530640 100644 --- a/packages/entity/test/nuxt/index.test.js +++ b/packages/entity/test/nuxt/index.test.js @@ -18,13 +18,55 @@ const nuxtMock = { }), } -test('Nuxt module', async () => { - nuxtMock.options = { - druxt: {}, - modules: [], - } - await DruxtEntityNuxtModule.setup({}, nuxtMock) - - expect(installModule).toHaveBeenCalledTimes(2) - expect(nuxtMock.hook).toHaveBeenCalledTimes(2) +describe('DruxtJS Nuxt module', () => { + beforeEach(() => jest.clearAllMocks()) + test('Nuxt module', async () => { + nuxtMock.options = { + druxt: {}, + modules: [], + } + await DruxtEntityNuxtModule.setup({}, nuxtMock) + + expect(installModule).toHaveBeenCalledTimes(2) + expect(nuxtMock.hook).toHaveBeenCalledTimes(2) + + // Find the hook function for 'components:dirs' + const componentsHooks = nuxtMock.hook.mock.calls.filter(call => call[0] === 'components:dirs') + expect(componentsHooks.length).toBe(1) + + const componentDirs = [] + // Execute the hook function to see what directories are added. + componentsHooks[0][1](componentDirs) + + expect(componentDirs).toContainEqual({ + path: expect.stringContaining('dist/components'), + ignore: ['fields'], + }) + }) + + test('Nuxt module - components.fields true', async () => { + nuxtMock.options = { + druxt: { + entity: { + components: { + fields: true, + }, + } + }, + modules: [], + } + await DruxtEntityNuxtModule.setup({}, nuxtMock) + + // Find the hook function for 'components:dirs' + const componentsHooks = nuxtMock.hook.mock.calls.filter(call => call[0] === 'components:dirs') + expect(componentsHooks.length).toBe(1) + + const componentDirs = [] + // Execute the hook function to see what directories are added. + componentsHooks[0][1](componentDirs) + + expect(componentDirs).toContainEqual({ + path: expect.stringContaining('dist/components/fields'), + }) + }) })