Unit testing &引用;意外标记<&引用;使用';npm测试';带有vue下拉列表和vue+;开玩笑
我一直从jest“SyntaxError:Unexpected token收到一条错误消息。在我看来,问题在于babel没有设置为转换您的vue文件Unit testing &引用;意外标记<&引用;使用';npm测试';带有vue下拉列表和vue+;开玩笑,unit-testing,vuejs2,jestjs,babel-jest,Unit Testing,Vuejs2,Jestjs,Babel Jest,我一直从jest“SyntaxError:Unexpected token收到一条错误消息。在我看来,问题在于babel没有设置为转换您的vue文件 在没有看到设置的情况下,很难提出具体的建议,但我建议您浏览这里的文档:我已经编辑了问题并将我的jest.config.js设置添加到其中。我已经按照vue页面上的文档进行了实现,但仍然出现了此错误。 import { shallowMount, createLocalVue } from '@vue/test-utils' import promo
在没有看到设置的情况下,很难提出具体的建议,但我建议您浏览这里的文档:我已经编辑了问题并将我的
jest.config.js
设置添加到其中。我已经按照vue页面上的文档进行了实现,但仍然出现了此错误。
import { shallowMount, createLocalVue } from '@vue/test-utils'
import promotionsForm from '@/components/promotions/PromotionsForm.vue'
import router from '@/router';
const localVue = createLocalVue();
jest.mock('@/store')
jest.mock('@/helpers', () => {
return {
startDate: jest.fn().mockReturnValue(
new Date(Date.now())
),
Helper: {
getCountryCurrencyCode () {
return 'USD'
}
}
}
})
describe('promotionsForm.vue', () => {
it('Past dates should be disabled', () => {
const wrapper = shallowMount(promotionsForm, {localVue, router})
expect(wrapper.find('.date-inline-picker:first-child input').exists()).toBe(true)
})
})
module.exports = {
moduleFileExtensions: ['js', 'json', 'vue', 'html'],
transform: {
'^.+\\.vue$': 'vue-jest',
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
'^.+\\.js$': 'babel-jest',
'^.+\\.html?$': 'html-loader-jest'
},
transformIgnorePatterns: [
'/node_modules/'
],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1'
},
snapshotSerializers: ['<rootDir>/node_modules/jest-serializer-vue'],
setupFiles: ['<rootDir>/test/unit/setup'],
testMatch: ['**/test/unit/**/*.spec.js'],
coverageDirectory: '<rootDir>/test/unit/coverage',
collectCoverageFrom: [
'src/**/*.{js,vue}',
'!src/main.js',
'!src/router/index.js',
'!**/node_modules/**'
]
}