Is there anyway to manually import / require functions like describe and it?
I'd like to use mocha without the commandline interface, in a regular browser. (I'm using JSPM as dependency manager)
I couldn't find documentation on this on the Mocha website.
@peteruithoven see here for using mocha in browser: https://mochajs.org/#running-mocha-in-the-browser
and you can do like this:
// es5 style
var testCase = require('mocha').describe;
var pre = require('mocha').before;
var assertions = require('mocha').it;
var assert = require('assert');
testCase('Array', function() {
pre(function() {
// ...
});
testCase('#indexOf()', function() {
assertions('should return -1 when not present', function() {
assert.equal([1,2,3].indexOf(4), -1);
});
});
});
// code ....
///es6 style with jspm(systemjs)
import { describe, before, it } from 'mocha';
import assert from 'assert';
describe('Array', function() {
before(function() {
// ...
});
describe('#indexOf()', function() {
it('should return -1 when not present', function() {
assert.equal([1,2,3].indexOf(4), -1);
});
});
});
Ah thanks, the extra examples you added where the docs I was missing.
I'm not able to get your JSPM(SystemJS) example working though, are you sure you've included all the details? Is there more info elsewhere?
Do I need to call setup() somewhere? The following piece of code looks hopeful, but I don't know that
pre-require event.
https://github.com/mochajs/mocha/blob/master/lib/mocha.js#L99
I've created a very minimal example of what I tried:
https://github.com/peteruithoven/jspm-mocha
Anyone?
see #956 for further discussion
Most helpful comment
@peteruithoven see here for using mocha in browser: https://mochajs.org/#running-mocha-in-the-browser
and you can do like this: