如何将requestAnimationFrame
设置为false
,将在条件语句中测试什么?
Object.defineProperty(window, 'requestAnimationFrame', {
value: ()=> {}
})
//need to be tested
if ('requestAnimationFrame' in window === false) {
window.scroll(0, destinationOffsetToScroll)
if (callback) {
callback()
}
return
}
答案 0 :(得分:0)
正如您在评论中指出的那样,您正在尝试嘲笑 window.requestanimationframe行为。我建议看看 https://github.com/alexreardon/raf-stub或 https://github.com/FormidableLabs/mock-raf:)
编辑:
delete window.requestAnimationFrame;
'requestAnimationFrame' in window === false
// true