UNPKG

chai-callslike

Version:

A simple sinon-chai assertion to validate many aspects of stub calls

29 lines (28 loc) 879 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.stubSuperConstructor = void 0; const sinon = require("sinon"); let cleanups = undefined; beforeEach(() => { cleanups = []; }); afterEach(() => { for (const cleanup of cleanups) { cleanup(); } cleanups = undefined; }); function stubSuperConstructor(cls) { if (cleanups === undefined) { throw new Error("Can't use that here: put it in a beforeEach or it clause"); } const prototypeBackup = Object.getPrototypeOf(cls); if (!prototypeBackup || prototypeBackup.name === '') { throw new Error('Object has no super prototype'); } const stub = sinon.stub(); Object.setPrototypeOf(cls, stub); cleanups.push(() => Object.setPrototypeOf(cls, prototypeBackup)); return stub; } exports.stubSuperConstructor = stubSuperConstructor;