Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
625 views
in Technique[技术] by (71.8m points)

使用vue-cli3构建项目,引入antd,进行jest测试,会报错

报错信息:
/node_modules/ant-design-vue/es/button/style/index.js:1

({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import '../../style/index.less';
                                                                                         ^^^^^^

SyntaxError: Cannot use import statement outside a module

采用了antd的按需加载,在组件中通过
import {Button} from 'ant-design-vue';
倒入antd组件


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

试试jest-mock

类似:

jest.mock(
  'rc-tabs/lib/ScrollableTabBarNode',
  () => () => null
)

或者看看有没有类似的地方:https://github.com/vueCompone...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...