diff --git a/packages/schema/test/nuxt/index.test.js b/packages/schema/test/nuxt/index.test.js new file mode 100644 index 000000000..8f0040959 --- /dev/null +++ b/packages/schema/test/nuxt/index.test.js @@ -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) + }) +}) diff --git a/packages/schema/test/nuxtModule.test.js b/packages/schema/test/nuxtModule.test.js deleted file mode 100644 index 2df09f2c5..000000000 --- a/packages/schema/test/nuxtModule.test.js +++ /dev/null @@ -1,45 +0,0 @@ -import DruxtSchemaNuxtModule, { DruxtSchema } from '../src' - -jest.mock('../src/schema') -let mock - -describe('Nuxt module', () => { - beforeEach(() => { - mock = { - addPlugin: jest.fn(), - addTemplate: jest.fn(), - nuxt: { - hook: async (hook, fn) => await fn() - }, - options: { - druxt: { - baseUrl: 'https://demo-api.druxtjs.org', - }, - }, - DruxtSchemaNuxtModule - } - - }) - - test('Default', async () => { - DruxtSchema.mockImplementation(() => ({ - get: () => ({ - schemas: { - 'node--page--default--view': {}, - 'node--article--default--view': undefined - } - }) - })) - await DruxtSchemaNuxtModule.call(mock) - expect(mock.addPlugin).toHaveBeenCalled() - expect(mock.addTemplate).toHaveBeenCalledTimes(1) - }) - - test('No schemas', async () => { - DruxtSchema.mockImplementation(() => ({ - get: () => ({ schemas: {} }) - })) - await DruxtSchemaNuxtModule.call(mock) - expect(mock.addTemplate).toHaveBeenCalledTimes(0) - }) -})