Mocking `document` in jest

后端 未结 8 1387
我在风中等你
我在风中等你 2020-11-29 04:12

I\'m trying to write tests for my web components projects in jest. I already use babel with es2015 preset. I\'m facing an issue while loading the js file. I have followed a

8条回答
  •  温柔的废话
    2020-11-29 04:29

    If you need to define test values for properties, there is a slightly more granular approach. Each property needs to be defined individually, and it's also necessary to make the properties writeable:

    Object.defineProperty(window.document, 'URL', {
      writable: true,
      value: 'someurl'
    });
    

    See: https://github.com/facebook/jest/issues/890

    This worked for me using Jest 21.2.1 and Node v8.11.1

提交回复
热议问题