配置jest让其window上存在ontouchstart 铁皮饭盒 2019-02-03 1,673 阅读1分钟 如果你的代码里有一段是这样的: // 是否支持touch事件 export const SUPPORT_TOUCH = ('ontouchstart' in window); 因为默认jest集成的jsdom的window上是没有ontouchstart属性的, 所以我们需要自己加一个: // jest.config.js module.exports = { ... globals: { ontouchstart: null } }; 现在在每个测试文件中, 都可以直接识别到ontouchstart了, 是不是很简单 🐳