Skip to content

在使用babel-plugin-component做按需引入element-ui,jest单元测试在引入element-ui组件的时候报错 #59

@yujie0707

Description

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

import Vue from 'vue';
import { Button } from 'element-ui'; // 执行到这一行的时候出错
import Country from '@/components/a.vue';


const localVue = createLocalVue();


localVue.use(Button);

Vue.prototype.$ELEMENT = { size: 'small' };


const wrapper = shallowMount(Country, {
  localVue,
  propsData: {
    visible: true,
  },
});

describe('选人组件', () => {
  const { vm } = wrapper;
  it('currentLeaf', () => {
    expect(vm.currentLeaf).toBe(undefined);
  });
});

报错内容如下

image

// babel.config.js
// 当注释掉plugins配置,上述内容才不报错
module.exports = {
  presets: [
    '@vue/app',
  ],
  // plugins: [
  //   [
  //     'component',
  //     {
  //       libraryName: 'element-ui',
  //       styleLibraryName: 'theme-chalk',
  //     },
  //   ],
  // ],
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions