Testing Unit Testing Framework Selection in Vue CLI
This test suite validates the unit testing configuration prompts in Vue CLI, specifically testing the selection and integration of Jest and Mocha testing frameworks. It ensures proper plugin installation and configuration based on user choices.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
vuejs/vue-cli
packages/@vue/cli/lib/promptModules/__tests__/unit.spec.js
jest.mock('fs')
jest.mock('inquirer')
const assertPromptModule = require('@vue/cli-test-utils/assertPromptModule')
const moduleToTest = require('../unit')
test('mocha', async () => {
const expectedPrompts = [
{
message: 'features',
choices: ['Unit Testing'],
check: [0]
},
{
message: 'Pick a unit testing solution',
choices: ['Jest', 'Mocha'],
choose: 0
}
]
const expectedOptions = {
plugins: {
'@vue/cli-plugin-unit-jest': {}
}
}
await assertPromptModule(
moduleToTest,
expectedPrompts,
expectedOptions,
{ pluginsOnly: true }
)
})
test('jest', async () => {
const expectedPrompts = [
{
message: 'features',
choices: ['Unit Testing'],
check: [0]
},
{
message: 'Pick a unit testing solution',
choices: ['Jest', 'Mocha'],
choose: 1
}
]
const expectedOptions = {
plugins: {
'@vue/cli-plugin-unit-mocha': {}
}
}
await assertPromptModule(
moduleToTest,
expectedPrompts,
expectedOptions,
{ pluginsOnly: true }
)
})