简体   繁体   English

带有vuejs import es6的开玩笑失败SyntaxError:意外令牌

[英]Jest with vuejs import es6 fails SyntaxError: Unexpected token <

Am using jest and am getting errors when importing a component 正在使用笑话,并且在导入组件时出错

import ContactForm from "../components/Contact/ContactForm.vue";
import { mount } from '@vue/test-utils'

describe("Contact Form", () => {

});

But now am getting an error SyntaxError: Unexpected token < at the import ContactForm 但是现在在导入ContactForm时出现错误SyntaxError:Unexpected token <

what do i need to add to have imports work 我需要添加什么才能进行导入工作

This is what is in my contact form 这是我的联系表格中的内容

<template>
    my form is here
</template>
<script>
    export default{
        data:()=>({
            contact_form:{
                first_name:'',
                last_name:'',
                email:'',
                message:'',
            }
        }),
        methods:{
            ContactUs(){
               //stuff
            }
        }
    }
</script>

It does not work like this out of the box. 开箱即用,它不起作用。 Usually you have Webpack and the vue-loader to process single file component files (.vue). 通常,您具有Webpack和vue-loader,用于处理单个文件组件文件(.vue)。 They do the work of splitting template, script and template. 他们完成拆分模板,脚本和模板的工作。 If you run jest, there is no Webpack involved so you do have to do a bit of configuration work and prepare your code for jest. 如果您运行jest,则不会涉及Webpack,因此您必须做一些配置工作并为jest准备代码。

There is a tutorial describing the process: https://hackernoon.com/jest-for-all-episode-1-vue-js-d616bccbe186 有一个描述该过程的教程: https : //hackernoon.com/jest-for-all-episode-1-vue-js-d616bccbe186

Take a look at that part: 看一下那部分:

What we need to do to make this work, is instruct Jest to preprocess the file > to return a JS object that will work for both us and Vue. 我们要做的就是指示Jest预处理文件>返回一个对我们和Vue均适用的JS对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM