如果你的代碼里有一段是這樣的:
// 是否支持touch事件
export const SUPPORT_TOUCH = ('ontouchstart' in window);
因?yàn)槟J(rèn)jest集成的jsdom的window上是沒有ontouchstart屬性的, 所以我們需要自己加一個(gè):
// jest.config.js
module.exports = {
...
globals: {
ontouchstart: null
}
};