util-ex
Version:
Browser-friendly enhanced util fully compatible with standard node.js
29 lines (26 loc) • 964 B
JavaScript
import sinonChai from "sinon-chai";
import sinon from "sinon";
import chai from "chai";
var assert = chai.assert;
var expect = chai.expect;
var should = chai.should();
chai.use(sinonChai);
import inject from '../src/inject.js';
describe("inject", function () {
it("should inject function and modifying arguments with beforeExec, afterExec", function () {
var orgExec = sinon.spy(() => 222);
var newArgs = inject.createArguments(['hi', 1]);
var beforeExec = sinon.spy(function () {
return newArgs;
});
var afterExec = sinon.spy();
var newExec = inject(orgExec, beforeExec, afterExec);
expect(newExec(1, 2)).to.be.equal(222);
beforeExec.should.have.been.calledOnce;
beforeExec.should.have.been.calledWith(1, 2);
orgExec.should.have.been.calledOnce;
orgExec.should.have.been.calledWith('hi', 1);
afterExec.should.have.been.calledOnce;
afterExec.should.have.been.calledWith('hi', 1, 222, false);
});
});