我正在MuiPickersUtilsProvider
使用@material-ui/pickers@
v-3.2.10
并使用如下:
import DateFnsUtils from '@date-io/date-fns'
import { DateTimePicker, MuiPickersUtilsProvider } from '@material-ui/pickers'
<MuiPickersUtilsProvider utils={DateFnsUtils}>
<DateTimePicker .../>
</MuiPickersUtilsProvider>
它适用于 UI,但在运行测试用例时会引发如下错误:
TypeError:Utils 不是构造函数
但是一旦我使用import * as DateFnsUtils from '@date-io/date-fns'
我们的测试用例,但同样的错误出现在 UI 上,
当我使用import {default as DateFnsUtils} from '@date-io/date-fns'
我们的测试用例时,但同样的错误出现在两个地方(UI 和测试用例)
我在下面的链接上找到了类似的讨论,但没有帮助
// setup file
var enzyme = require('enzyme');
var Adapter = require('enzyme-adapter-react-16');
require('jest-canvas-mock')
enzyme.configure({ adapter: new Adapter() });
crypto = require('@trust/webcrypto')
// fetch undefined
const fetchPolifill = require('whatwg-fetch')
global.fetch = fetchPolifill.fetch
global.Request = fetchPolifill.Request
global.Headers = fetchPolifill.Headers
global.Response = fetchPolifill.Response
function noOp () { }
if (typeof window.URL.createObjectURL === 'undefined') {
Object.defineProperty(window.URL, 'createObjectURL', { value: noOp})
}