对象定义属性:如何将requestAnimationFrame设置为false?

时间:2018-10-15 09:15:38

标签: javascript jestjs

如何将requestAnimationFrame设置为false,将在条件语句中测试什么?

Object.defineProperty(window, 'requestAnimationFrame', {
    value: ()=> {}
})


//need to be tested

if ('requestAnimationFrame' in window === false) {
            window.scroll(0, destinationOffsetToScroll)
            if (callback) {
                callback()
            }
            return
        }

1 个答案:

答案 0 :(得分:0)

  

正如您在评论中指出的那样,您正在尝试嘲笑   window.requestanimationframe行为。我建议看看   https://github.com/alexreardon/raf-stub或   https://github.com/FormidableLabs/mock-raf:)

编辑:

delete window.requestAnimationFrame;
'requestAnimationFrame' in window === false
// true