How to test custom web component with jest?

后端 未结 5 732
栀梦
栀梦 2021-01-06 08:54

I would like to test some custom web components and use jest.js as test runner (due to its support for ES6).

Chromium supports commands like

window.c         


        
5条回答
  •  醉话见心
    2021-01-06 09:23

    I have created a DOM that supports server side rendering of web components. It also supports testing web components with Jest.

    DOM:

    https://www.npmjs.com/package/happy-dom

    Jest environment:

    https://www.npmjs.com/package/jest-environment-happy-dom

    To install it

    npm install jest-environment-happy-dom --save-dev

    To use it:

    Edit your package.json to include the Jest environment:

    {
        "scripts": {
            "test": "jest --env=jest-environment-happy-dom"
        }
    }
    

提交回复
热议问题