Vue.js 为什么vue jest不';无法在我的测试文件中正确安装引导vue?
提前感谢您的回答 这里是我的问题:我想开玩笑地进行单元测试 我测试了我的组件(一个登录表单),并在这个组件中使用:Bootstrap vue。 因此,在我的测试文件中,我包括Bootrap vue、vue测试utils中的createLocalVue 但我有一个错误: TypeError:无法读取未定义的属性“installed” 和我的配置文件: jest.config.js:Vue.js 为什么vue jest不';无法在我的测试文件中正确安装引导vue?,vue.js,jestjs,bootstrap-vue,Vue.js,Jestjs,Bootstrap Vue,提前感谢您的回答 这里是我的问题:我想开玩笑地进行单元测试 我测试了我的组件(一个登录表单),并在这个组件中使用:Bootstrap vue。 因此,在我的测试文件中,我包括Bootrap vue、vue测试utils中的createLocalVue 但我有一个错误: TypeError:无法读取未定义的属性“installed” 和我的配置文件: jest.config.js: const path = require('path') module.exports = { rootDir
const path = require('path')
module.exports = {
rootDir: path.resolve(__dirname, '../../'),
setupFiles: ['setup.js'],
moduleFileExtensions: [
'js',
'json',
'vue',
'ts'
],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
'vue$': "vue/dist/vue.common.js",
},
transform: {
'^.+\\.js$': 'babel-jest',
'.*\\.(vue)$': 'vue-jest'
},
testPathIgnorePatterns: [
'<rootDir>/test/coverage/',
'<rootDir>/dist/',
'<rootDir>/node_modules/'
],
//snapshotSerializers: ['<rootDir>/node_modules/jest-serializer-vue'],
setupFiles: ['<rootDir>/test/unit/setup'],
coverageDirectory: '<rootDir>/test/unit/coverage',
collectCoverageFrom: [
'src/**/*.{js,vue}',
'!src/main.js',
'!src/router/index.js',
'!**/node_modules/**'
],
transformIgnorePatterns: ['node_modules/core.js','node_modules/babel-runtime','node_modules/vue',"node_modules/(?!bootstrap-vue)"]
}
const path=require('path'))
module.exports={
rootDir:path.resolve(uu dirname,../../),
setupFiles:['setup.js'],
moduleFileExtensions:[
"js",,
“json”,
“vue”,
“ts”
],
模块映射:{
“^@/(.*)$”:“/src/$1”,
“vue$”:“vue/dist/vue.common.js”,
},
转换:{
“^.+\\.js$”:“巴贝尔笑话”,
“.\\\(vue)$”:“vue笑话”
},
testPathIgnorePatterns:[
“/test/coverage/”,
“/dist/”,
“/node_modules/”
],
//快照序列化程序:['/node_modules/jest序列化程序vue'],
设置文件:['/test/unit/setup'],
coverage目录:'/test/unit/coverage',
收款人:[
“src/***.{js,vue}”,
“!src/main.js”,
“!src/router/index.js”,
“!**/node_modules/**”
],
transformIgnorePatterns:['node_modules/core.js'、'node_modules/babel runtime'、'node_modules/vue'、“node_modules/(?!bootstrap vue)”]
}
B.法律改革委员会
{
"presets": [
"@babel/preset-flow",
"@babel/preset-react",
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
/*{
"modules": false,
"targets": {
"browsers": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}
}*/
]
],
"plugins": [
"transform-vue-jsx",
[
"@babel/plugin-transform-runtime",
{
"corejs": 2
}
],
"babel-plugin-styled-components",
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-syntax-import-meta",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-json-strings",
"transform-class-properties",
"syntax-class-properties",
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
],
"@babel/plugin-proposal-function-sent",
"@babel/plugin-proposal-export-namespace-from",
"@babel/plugin-proposal-numeric-separator",
"@babel/plugin-proposal-throw-expressions"
]
}
{
“预设”:[
“@babel/预设流量”,
“@babel/reset react”,
[
“@babel/preset env”,
{
“目标”:{
“节点”:“当前”
}
}
/*{
“模块”:错误,
“目标”:{
“浏览器”:[
"> 1%",
“最后两个版本”,
“不要ie确保错误指向localVue.use(BootstrapVue)
行而不是相邻行。似乎无法在install.installed中定义install
,至少对于当前版本,请确保您使用的是最新版本。另外,为什么vue.use(Vuetify)中无法定义install
。”
而不是localVue
?感谢您的回答,我使用Vue.use(Vuetify)是因为localVue.use(Vuetify)给了我一个错误。我确信这是BootstrapVue,因为当我在main.js中输入console.log时(服务器运行时执行文件),install.installed存在,不在我的文件测试中。我使用的是最新版本的vue和引导,我今天早上安装的。我不确定你的意思。有几个use
调用,每个调用都可能触发此错误,因为installed
属性通常特定于vue插件(这个错误也不应该发生在编写良好的插件中,这里没有办法不定义install
).Jest可能会因为源代码映射问题而指向错误的行。您需要可靠地将问题缩小到特定的插件初学者。vuetify的btu和vuex它可以工作。我如何知道哪个插件不工作?如果我理解您的意思是如何知道它真的可以工作,请逐个注释它们并取消注释e、 目前,您是唯一可以这样做的人。问题是其他用户目前无法识别,因为bootstrap vue似乎不可能触发此错误,请参阅上面的链接。如果问题仍然存在,请提供无法访问您的项目的其他用户可以复制的问题。
const path = require('path')
module.exports = {
rootDir: path.resolve(__dirname, '../../'),
setupFiles: ['setup.js'],
moduleFileExtensions: [
'js',
'json',
'vue',
'ts'
],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
'vue$': "vue/dist/vue.common.js",
},
transform: {
'^.+\\.js$': 'babel-jest',
'.*\\.(vue)$': 'vue-jest'
},
testPathIgnorePatterns: [
'<rootDir>/test/coverage/',
'<rootDir>/dist/',
'<rootDir>/node_modules/'
],
//snapshotSerializers: ['<rootDir>/node_modules/jest-serializer-vue'],
setupFiles: ['<rootDir>/test/unit/setup'],
coverageDirectory: '<rootDir>/test/unit/coverage',
collectCoverageFrom: [
'src/**/*.{js,vue}',
'!src/main.js',
'!src/router/index.js',
'!**/node_modules/**'
],
transformIgnorePatterns: ['node_modules/core.js','node_modules/babel-runtime','node_modules/vue',"node_modules/(?!bootstrap-vue)"]
}
{
"presets": [
"@babel/preset-flow",
"@babel/preset-react",
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
/*{
"modules": false,
"targets": {
"browsers": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}
}*/
]
],
"plugins": [
"transform-vue-jsx",
[
"@babel/plugin-transform-runtime",
{
"corejs": 2
}
],
"babel-plugin-styled-components",
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-syntax-import-meta",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-json-strings",
"transform-class-properties",
"syntax-class-properties",
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
],
"@babel/plugin-proposal-function-sent",
"@babel/plugin-proposal-export-namespace-from",
"@babel/plugin-proposal-numeric-separator",
"@babel/plugin-proposal-throw-expressions"
]
}