首页 > 解决方案 > 使用它来测试 vuejs/typescript 组件时的笑话错误

问题描述

我使用 vue cli 3 创建了一个带有 typescript 和 jest 的应用程序以进行单元测试。但我得到了这个错误

SyntaxError: Unexpected token m in JSON at position 0
        at JSON.parse (<anonymous>)

有什么解释吗?(我没有在 jest.config 或 tsconfig 中进行任何更改)

顺便说一句,如果将 lang="ts" 更改为 lang="js" 它可以工作。

代码组件(可能的简单组件):

<template>
    <div>{{hello}}</div>
</template>

<script lang="ts">
import Vue from 'vue'
export default Vue.extend({
    data () {
        return {
            message: 'hello'
        }
    }
})
</script>

测试文件

import { shallowMount, Wrapper } from '@vue/test-utils';

import AComp from '@/components/uikit/AComp.vue';

describe('DropdownButton', () => {
    beforeEach(() => {
        const wrapper = shallowMount(AComp);
    });

    it("works", () => {
        expect(true).toBeTruthy()
    })
});

标签: typescriptvue.jsjestjs

解决方案


推荐阅读