酶打字稿–无法设置[object Event]的属性目标,该对象仅在Function.assign

时间:2019-11-13 16:05:27

标签: typescript enzyme preact

代码:

...
wrapper.find('input').simulate('input', { target: {value: 's'}})

cmd:

jest test

结果

Cannot set property target of [object Event] which has only a getter at Function.assign

node_modules / enzyme-adapter-preact-pure / build / src / MountRenderer.js中的错误

    var event = new Event(eventName, {
        bubbles: args.bubbles,
        composed: args.composed,
        cancelable: args.cancelable,
    });
    Object.assign(event, args);

事件是来自typescript / libs / lib.d.ts的接口

interface Event {
    ...
    readonly target: EventTarget | null;
    ...
}

目标是只读,如何设置自定义目标?

package.json

"@types/jest": "^24.0.19",
"@types/jquery": "^3.3.31",
"enzyme": "^3.10.0",
"enzyme-adapter-preact-pure": "^2.1.0",
"enzyme-to-json": "^3.4.3",
"jest": "^24.9.0",
"preact": "^8.4.2",
"preact-context": "^1.1.4",
"preact-redux": "^2.0.3",
"redux": "^4.0.1",
"ts-jest": "^24.1.0",
"ts-loader": "^4.5.0",
"typescript": "^3.5.3",
"webpack": "^4.39.1",
"webpack-cli": "^3.3.9"

0 个答案:

没有答案