Jest URL.createObjectURL is not a function

前端 未结 4 1516
[愿得一人]
[愿得一人] 2021-01-17 07:39

I\'m developping a reactJs application. I\'m using jest to test my application. I want to test a function that download a blob.

But unfortunately I receve this error

4条回答
  •  醉酒成梦
    2021-01-17 08:06

    jsdom, the JavaScript implementation of the WHATWG DOM used by jest doesn't implement this method yet.

    You can find an open ticket about this exact issue on their github page where some workarounds are provided in comments. But if you need the blobURL to actually work you'll have to wait this FR is solved.

    Workaround proposed in the comments of the issue for jest:

    function noOp () { }
    if (typeof window.URL.createObjectURL === 'undefined') { 
      Object.defineProperty(window.URL, 'createObjectURL', { value: noOp})
    }
    

提交回复
热议问题