Skip to main content

Testing

Testing ensures your code functions as you intend and saves you from tedious debugging.

See the Starter Kits documentation for an easy to use setup with a fully pre-configured testing environment that works great for testing Lit components.

Lit is a standard modern Javascript library, and you can use virtually any Javascript testing framework to test your Lit code. There are many popular options, including Jest, Karma, Mocha, Jasmine, and Web Test Runner.

There are a few things you'll want to make sure your testing environment supports to effectively test your Lit code.

Lit components are designed to run in the browser so testing should be conducted in a browser environment. Tools specifically focusing on testing node code may not be a good fit.

While it's possible to test without a browser by shimming DOM calls, we don't recommend this approach since it won't test the code in the way your users experience it.

The test environment you use must have support for using modern Javascript, including using modules with bare module specifiers, or else down-leveling modern Javascript appropriately. See the Requirements for legacy browsers documentation for more details.

To test on older browsers, your test environment will need to load some polyfills, including the web components polyfills and Lit's polyfill-support module. See the Polyfills documentation for more details.

We recommend using Web Test Runner since it is specifically designed to test modern web libraries like Lit using modern web features like custom elements and shadow DOM. See the Getting Started documentation for Web Test Runner.

In order to support older browsers, you need to configure Web Test Runner as follows:

Install @web/dev-server-legacy:

Setup web-test-runner.config.js: