Jest Enzyme无法在mount()中找到导入的功能 [英] Jest Enzyme impossible to locate imported function in mount()
本文介绍了Jest Enzyme无法在mount()中找到导入的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须安装一个使用库中函数的组件.该函数在componentDidMount循环中使用.一切看起来都像这样:
I have to mount a component that uses a function from library. The function is used in the componentDidMount cycle. Everything looks somewhat like this:
import * as React from 'react';
import * as dayjs from 'dayjs';
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.slider = null;
}
componentDidMount() {
this.setupValues();
}
setupValues() {
this.slider = {
...,
format: dayjs(val).format(...)
}
}
render() {...}
}
现在我要在测试中使用的包装器是:
Now the wrapper that I am trying to use in my test is:
const wrapper = mount(<MyComponent />);
...
遗憾的是,该测试甚至无法运行,因为安装功能失败:dayjs is not a function
Sadly, the test does not even run because the mount function fails saying: dayjs is not a function
为什么找不到导入的dayjs函数?
Why does it fail to find the imported dayjs function?
推荐答案
dayjs
函数是 default
导出模块的.
The dayjs
function is the default
export of the module.
这意味着您需要导入它像这样:
import dayjs from 'dayjs';
这篇关于Jest Enzyme无法在mount()中找到导入的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文