Skip to content

Testing

MatthewThe edited this page Mar 12, 2024 · 5 revisions

There are a number of testing tools for Javascript projects, including Jest and Mocha. We use @open-wc/testing, since it is installed automatically when initializing an Open Web Components project.
The syntax for writing tests is easy. For example, to test that a function sum can correctly sum up two numbers, you would write something like this:

it('can add two numbers together', function () {
  expect(sum(39,3)).to.equal(42);
});

Examples/tutorials:

In addition to the @open-wc/testing package, we use Playwright to run your tests in different browsers. Actually, you could also use Playwright to write full-fledged end-to-end tests, so we are not using all of its features here.

Same as for demoing, please use Fixtures to feed your tests with data.

We have set up husky to run all tests whenever you want to commit code. husky also runs ESLint and Prettier to clean up and format your code in a consistent manner.

Clone this wiki locally