1. steal-mocha
A package for Mocha and StealJS
steal-mocha
Package: steal-mocha
Created by: stealjs
Last modified: Mon, 27 Jun 2022 00:14:34 GMT
Version: 2.0.1
License: MIT
Downloads: 137
Repository: https://github.com/stealjs/steal-mocha

Install

npm install steal-mocha
yarn add steal-mocha

Build Status
npm version

steal-mocha

Provides an easy way to automatically run Mocha tests using StealJS.

Use

Add the Steal tag to your page

 <script src="node_modules/steal/steal.js"
  mocha="bdd"
  main="test/test"></script>

This will do the equivalent of

 mocha.setup("bdd");

and your tests will automatically be ran.

Writing tests

When you write tests just be sure to import steal-mocha.

 import "steal-mocha";

describe("Foo", function(){
  it("bar", function(){
    assert("yay!");
  });
});

Use with Bower / manually

If you are not using NPM the following configuration is necessary:

 System.config({
  "paths": {
      "steal-mocha": "path/to/steal-mocha/steal-mocha.js",
      "steal-mocha/*": "path/to/steal-mocha/*.js",
      "mocha": "path/to/mocha/mocha.js",
      "mocha/mocha.css": "path/to/mocha/mocha.css"
  },
  "meta": {
      "mocha": {
          "format": "global",
          "exports": "mocha",
          "deps": [
              "steal-mocha/add-dom"
          ]
      }
  }
});

mocha.opts

Mocha's runner allows for a mocha.opts file,
specifying addition options such as checkLeaks(). steal-mocha does not parsed
a mocha.opts file, however allows the specification of a startup script.

This is similar to the --require option in mocha.opts.

 <script src="node_modules/steal/steal.js"
  mocha-require="test/setup"
  main="test/test"></script>

The path in data-mocha-require is a module name.

test/setup.js

 const chai = require('chai');
const sinon = require('sinon');

module.exports = function(mocha) {
  sinon.assert.expose(chai.assert, { prefix: '' });
};

The above example extends Chai's assertion library with SinonJS assertions.

License

MIT

Dependencies

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code