UNPKG

@rxjs-stuff/marbles

Version:

A set of plugins that provide a natural feeling integration with Mocha and Chai for RxJS "marbles" testing.

71 lines 3.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setUpMochaMarbles = void 0; const marbles_1 = require("@rxjs-stuff/marbles"); function setUpMarblesContext(config, context) { function makeMarblesTest(test) { return function marblesTest(title, fn) { if (typeof fn === 'function') { return test(title, function () { if (!this.test.parent.marblesEnabled) { return fn.call(this, undefined); } if (typeof config.beforeEach === 'function') { config.beforeEach(marbles_1.MarblesHelpers, this); } const returnValue = marbles_1.MarblesHelpers.run((helpers) => { fn.call(this, helpers); }); if (typeof config.afterEach === 'function') { config.afterEach(marbles_1.MarblesHelpers, this); } return returnValue; }); } return test(title, fn); }; } function makeMarblesSuite(context, action, marblesEnabled) { return function marblesSuite(title, fn) { const { it, xit } = context; context.it = makeMarblesTest(it); context.it.only = makeMarblesTest(it.only); context.it.skip = makeMarblesTest(it.skip); context.it.noMarbles = it; context.xit = makeMarblesTest(xit); context.xit.noMarbles = xit; return action(title, function () { this.marblesEnabled = typeof marblesEnabled === 'undefined' ? this.parent.marblesEnabled : marblesEnabled; if (this.marblesEnabled) { marbles_1.marblesTesting(); return fn.call(this, marbles_1.MarblesHelpers); } return fn.call(this, undefined); }); }; } const describe = context.describe; context.describe = makeMarblesSuite(context, describe); context.describe.only = makeMarblesSuite(context, describe.only); context.describe.skip = makeMarblesSuite(context, describe.skip); context.describe.marbles = makeMarblesSuite(context, describe, true); context.describe.marbles.only = makeMarblesSuite(context, describe.only, true); context.describe.marbles.skip = makeMarblesSuite(context, describe.skip, true); context.describe.noMarbles = makeMarblesSuite(context, describe, false); context.xdescribe.marbles = makeMarblesSuite(context, context.xdescribe, true); } const setUpMochaMarbles = (mocha, config, targetContext) => { marbles_1.MarblesHelpers.init(config.assertDeepEqual); const setupContext = setUpMarblesContext.bind(undefined, config); const bdd = mocha.interfaces.bdd.bind(mocha.interfaces); mocha.interfaces.bdd = function marblesBddInterface(suite) { bdd(suite); const { EVENT_FILE_PRE_REQUIRE } = mocha.Suite.constants; suite.on(EVENT_FILE_PRE_REQUIRE, setupContext); }; if (targetContext) { setupContext(targetContext); } }; exports.setUpMochaMarbles = setUpMochaMarbles; //# sourceMappingURL=mocha-marbles.js.map