Files
vue-cli/packages/@vue/cli-plugin-unit-mocha/__tests__/mochaGenerator.spec.js
T

89 lines
2.2 KiB
JavaScript

const generateWithPlugin = require('@vue/cli-test-utils/generateWithPlugin')
test('base', async () => {
const { pkg, files } = await generateWithPlugin([
{
id: 'unit-mocha',
apply: require('../generator'),
options: {}
},
// mock presence of the eslint plugin
{
id: 'eslint',
apply: () => {},
options: {}
}
])
expect(pkg.scripts['test:unit']).toBe('vue-cli-service test:unit')
expect(pkg.devDependencies).toHaveProperty('@vue/test-utils')
expect(files['tests/unit/.eslintrc.js']).toMatch('mocha: true')
const spec = files['tests/unit/example.spec.js']
expect(spec).toMatch(`import { expect } from 'chai'`)
expect(spec).toMatch(`expect(wrapper.text()).to.include(msg)`)
})
test('with TS', async () => {
const { files } = await generateWithPlugin([
{
id: 'unit-mocha',
apply: require('../generator'),
options: {}
},
// mock presence of the ts plugin
{
id: 'typescript',
apply: () => {},
options: {}
}
])
const spec = files['tests/unit/example.spec.ts']
expect(spec).toMatch(`import { expect } from 'chai'`)
expect(spec).toMatch(`expect(wrapper.text()).to.include(msg)`)
})
test('bare', async () => {
const { files } = await generateWithPlugin([
{
id: 'unit-mocha',
apply: require('../generator'),
options: {}
},
{
id: '@vue/cli-service',
apply: () => {},
options: { bare: true }
}
])
const spec = files['tests/unit/example.spec.js']
expect(spec).toMatch(`const wrapper = shallowMount(App)`)
expect(spec).toMatch(`expect(wrapper.text()).to.include(\`Welcome to Your Vue.js App\`)`)
})
test('TS + bare', async () => {
const { files } = await generateWithPlugin([
{
id: 'unit-mocha',
apply: require('../generator'),
options: {}
},
{
id: 'typescript',
apply: () => {},
options: {}
},
{
id: '@vue/cli-service',
apply: () => {},
options: { bare: true }
}
])
const spec = files['tests/unit/example.spec.ts']
expect(spec).toMatch(`const wrapper = shallowMount(App)`)
expect(spec).toMatch(`expect(wrapper.text()).to.include(\`Welcome to Your Vue.js + TypeScript App\`)`)
})