使用VueMaterials MdInput时运行Jest测试时出错

时间:2019-08-09 09:33:40

标签: vue.js jestjs vue-material

这是一个小例子

<template>
    <div>
        <h1>Test</h1>

        <md-field md-clearable class="md-toolbar-section-end">
            <md-input placeholder="Search"/>
        </md-field>
    </div>
</template>

<script>
    export default {
        name: "Test"
    }
</script>
import Vue from 'vue';
import {mount} from '@vue/test-utils';
import Test from '../../../../resources/js/components/admin/_shared/Test';
import VueMaterial from 'vue-material';
import expect from "expect";

Vue.use(VueMaterial);

describe('Test', () => {

    it('should test 1', () => {
        const wrapper = mount(Test);
        expect(wrapper.find('h1').text()).toEqual('Test');
    });

    it('should test 2', () => {
        const wrapper = mount(Test);
        expect(wrapper.find('h1').text()).toEqual('Test');
    });
});

运行测试时,第一个通过测试,然后第二个通过测试,错误为[Vue warn]: Error in config.errorHandler: "TypeError: Cannot read property '$options' of undefined"

我正在使用Jest提供的@vue/cli-service进行测试

我的jest.config.js

require('jsdom-global')();
const Vue = require('vue');
Vue.config.productionTip = false;
require("@babel/register")({
    presets: ["env"]
});
module.exports = {
    moduleFileExtensions: [
        'js',
        'jsx',
        'json',
        'vue'
    ],
    transform: {
        '^.+\\.vue$': 'vue-jest',
        '.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
        '^.+\\.jsx?$': 'babel-jest'
    },
    transformIgnorePatterns: [
        '/node_modules/'
    ],
    moduleNameMapper: {
        '^@/(.*)$': '<rootDir>/src/$1'
    },
    snapshotSerializers: [
        'jest-serializer-vue'
    ],
    testMatch: [
        '**/tests/JavaScript/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)'
    ],
    testURL: 'http://localhost/',
    watchPlugins: [
        'jest-watch-typeahead/filename',
        'jest-watch-typeahead/testname'
    ]
};

我可以做些什么来使用md-input来测试组件吗?

0 个答案:

没有答案