Skip to content

Commit

Permalink
chore(#693): update druxt-schema tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Decipher committed Aug 13, 2024
1 parent f139c90 commit b19782f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 45 deletions.
53 changes: 53 additions & 0 deletions packages/schema/test/nuxt/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { DruxtSchema } from '../../src'
import DruxtSchemaNuxtModule from '../../src/nuxt'

jest.mock('@nuxt/kit', () => ({
addTemplate: jest.fn(),
addPluginTemplate: jest.fn(),
defineNuxtModule: (module) => module,
installModule: jest.fn(),
useLogger: jest.fn(() => ({
success: jest.fn(),
})),
}))

import { addPluginTemplate, addTemplate } from '@nuxt/kit'

jest.mock('../../src/schema')
let nuxtMock

describe('Nuxt module', () => {
beforeEach(() => {
jest.clearAllMocks()
nuxtMock = {
hook: async (hook, fn) => await fn(),
options: {
druxt: {
baseUrl: 'https://demo-api.druxtjs.org',
},
},
}
})

test('Default', async () => {
DruxtSchema.mockImplementation(() => ({
get: () => ({
schemas: {
'node--page--default--view': {},
'node--article--default--view': undefined
}
})
}))
await DruxtSchemaNuxtModule.setup({}, nuxtMock)
expect(addPluginTemplate).toHaveBeenCalled()
expect(addTemplate).toHaveBeenCalledTimes(1)
})

test('No schemas', async () => {
DruxtSchema.mockImplementation(() => ({
get: () => ({ schemas: {} })
}))
await DruxtSchemaNuxtModule.setup({}, nuxtMock)
expect(addTemplate).toHaveBeenCalledTimes(0)
})
})
45 changes: 0 additions & 45 deletions packages/schema/test/nuxtModule.test.js

This file was deleted.

0 comments on commit b19782f

Please sign in to comment.