New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@web/test-runner-mocha

Package Overview
Dependencies
Maintainers
6
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@web/test-runner-mocha

Mocha test framework for Web Test Runner

0.2.10
Source
npm
Version published
Weekly downloads
79K
0.84%
Maintainers
6
Weekly downloads
 
Created
Source

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

Writing JS tests

Mocha relies on global variables, in any JS test file describe and it are available globally and can be used directly:

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

Writing HTML tests

If you're writing tests as HTML, you can import this library to run tests with mocha:

<html>
  <body>
    <script type="module">
      // after importing "@web/test-runner-mocha", describe and it will be available globally
      import { runTests } from '@web/test-runner-mocha';

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

      // you need to call runTests() when you've loaded all your tests
      runTests();
    </script>
  </body>
</html>

Configuring mocha options

You can configure mocha options using the testFramework.config option:

module.exports = {
  testFramework: {
    config: {
      ui: 'bdd',
      timeout: '2000',
    },
  },
};

The config entry accepts any of the official mocha browser options.

Libraries

@open-wc/testing is a general purpose library, including assertions via chai, HTML test fixtures, a11y tests and test helpers.

It is an opinionated implementation which brings together multiple libraries. You could also use the individual libraries together:

For stubbing and mocking, we recommend sinon which ships an es module variant out of the box:

import { stub, useFakeTimers } from 'sinon';

Keywords

web

FAQs

Package last updated on 29 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts