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('setup hook', async () => {
const hooks = {
setup: jest.fn()
}
await NuxtCommand.run(dev, [], hooks)
expect(hooks.setup).toHaveBeenCalledWith({
argv: [],
cmd: dev,
rootDir: path.resolve('.')
})
})
test('setup hook (custom CLI options & rootDir)', async () => {
const hooks = {
setup: jest.fn()
}
await NuxtCommand.run(dev, ['-p', '3001', 'path/to/project'], hooks)
expect(hooks.setup).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
}))
})
})