JSPM

  • Created
  • Published
  • Downloads 88172
  • Score
    100M100P100Q167147F
  • License MIT

Mocha test framework for Web Test Runner

Package Exports

  • @web/test-runner-mocha

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@web/test-runner-mocha) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Test Runner Mocha

Test framework implementation of Mocha for Web Test Runner

See @web/test-runner for a default implementation and CLI for the test runner.

Writing tests

Mocha relies on global variables, in any test file describe and it are available globally:

describe('my test', () => {
  it('foo is bar', () => {
    if ('foo' !== 'bar') {
      throw new Error('foo does not equal bar');
    }
  });
});

Configuring mocha to use TDD is not yet supported.

Writing assertions

You can use any assertion library as long as it works in the browser. For example this es module version of chai:

import { expect } from '@bundled-es-modules/chai';

test('foo is bar', () => {
  expect(foo).to.equal('bar');
});

Creating HTML test fixture

To scaffold an HTML test fixture you can use the @open-wc/testing-helpers library.

import { fixture, html } from '@open-wc/testing-helpers';
import { expect } from '@bundled-es-modules/chai';
import '../my-element.js';

describe('my-element', () => {
  it('should render properly', async () => {
    const element = await fixture(html` <my-element></my-element> `);
    expect(element.localName).to.equal('my-element');
  });
});