Nuxt/packages/cli/test/unit/hooks.test.js

53 lines
1.1 KiB
JavaScript
Raw Normal View History

import path from 'path'
2019-08-24 14:15:08 +00:00
import { NuxtCommand } from '../utils'
describe('dev', () => {
let dev
beforeAll(async () => {
dev = await import('../../src/commands/dev').then(m => m.default)
})
afterEach(() => jest.clearAllMocks())
test('run:before hook', async () => {
const hooks = {
'run:before': jest.fn()
}
await NuxtCommand.run(dev, [], hooks)
expect(hooks['run:before']).toHaveBeenCalledWith({
argv: [],
cmd: dev,
rootDir: path.resolve('.')
})
})
test('run:before hook (custom CLI options & rootDir)', async () => {
const hooks = {
'run:before': jest.fn()
}
await NuxtCommand.run(dev, ['-p', '3001', 'path/to/project'], hooks)
expect(hooks['run:before']).toHaveBeenCalledWith({
argv: ['-p', '3001', 'path/to/project'],
cmd: dev,
rootDir: path.resolve('path/to/project')
})
})
2019-08-24 14:15:08 +00:00
test('config hook', async () => {
const hooks = {
config: jest.fn()
}
await NuxtCommand.run(dev, [], hooks)
expect(hooks.config).toHaveBeenCalledWith(expect.objectContaining({
_cli: true
}))
})
})