Skip to content

Instantly share code, notes, and snippets.

@bvanderlaan
Created September 6, 2018 00:25
Show Gist options
  • Save bvanderlaan/24fbfd95c036d8d9235817125ec8392d to your computer and use it in GitHub Desktop.
Save bvanderlaan/24fbfd95c036d8d9235817125ec8392d to your computer and use it in GitHub Desktop.
How to run Mocha in CoderPad

When using CoderPad to write code in the browser, say your on the go and just need to write some code, and that code happens to be JavaScript and you want to run a Mocha test here is what you need to do:

'use strict';

const { expect } = require('chai');
const Mocha = require('mocha');
const mocha = new Mocha({ui: 'bdd'});

// CODE ///////////////

// write your code here, test it below

// TEST ////////////////

// Bit of a hack, sorry!
mocha.suite.emit('pre-require', this, 'solution', mocha);

describe('My Tests', () => {
  it('should run', () => {
    expect(2).to.equal(2);
  });
});

mocha.run(function() {});

I snagged this from here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment