Testing is an important part of any software project. We have collected a set of libraries, tools and best practices to get you started with testing.
Our setup is aimed specifically at working with minimal tooling, using the native es module loader of the browser just like our developing setup. We have special helper functions available for testing web components, but our setup works without web components as well.
The easiest way to set up testing in your project is to use our project scaffolding. You can use this to create a new project or to upgrade an existing project:
npm init @open-wc
To set up testing in your project manually, you will need to follow the instructions of the separate tools and packages below.
#Step by step guide
To help you get started with testing, we recommend reading this article for a great step by step guide.
#Web Test Runner
See the this guide for a step by step guide how to set up the test runner.
When testing with web test runner, we recommend the following libraries:
- mocha for setting up the testing structure.
- chai for doing assertions
- @open-wc/testing-helpers for setting up test fixtures and helper functions
- @open-wc/semantic-dom-diff for snapshot testing the rendered HTML
- @open-wc/chai-axe-a11y for testing accessibility
To use these testing libraries, we recommend @open-wc/testing. This is an opinionated package that combines and configures many of these testing libraries, to minimize the amount of ceremony required to set up tests. For example, it exports chai with plugins already registered.
A large part of the tests that are traditionally done with selenium can be done with Web Test Runner. However, there are still tests that should be run after an application has been deployed. We're still looking for good solutions here, help us improve this documentation by making a pull request!