Skip to content

Commit

Permalink
chore(#693): improved test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Decipher committed Sep 19, 2024
1 parent 0f0cf4f commit 0828671
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
8 changes: 6 additions & 2 deletions packages/blocks/test/nuxt/index.test.js
Original file line number Diff line number Diff line change
@@ -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])
}),
Expand All @@ -22,4 +23,7 @@ test('Nuxt module', async () => {
druxt: {}
}
await DruxtBlocksNuxtModule.setup({}, nuxtMock)

expect(installModule).toHaveBeenCalledTimes(1)
expect(nuxtMock.hook).toHaveBeenCalledTimes(2)
})
4 changes: 4 additions & 0 deletions packages/druxt/test/nuxt/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/entity/test/nuxt/index.test.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -23,4 +24,7 @@ test('Nuxt module', async () => {
modules: [],
}
await DruxtEntityNuxtModule.setup({}, nuxtMock)

expect(installModule).toHaveBeenCalledTimes(2)
expect(nuxtMock.hook).toHaveBeenCalledTimes(2)
})
3 changes: 2 additions & 1 deletion packages/router/test/nuxt/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const nuxtMock = {
}),
}


test('Nuxt module', async () => {
nuxtMock.options = {
build: {},
Expand All @@ -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)
Expand Down

0 comments on commit 0828671

Please sign in to comment.