Module

x/chai/lib/chai/utils/overwriteMethod.js>overwriteMethod

BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.
Latest
function overwriteMethod
import { overwriteMethod } from "https://dotland.deno.dev/x/chai@v5.1.2/lib/chai/utils/overwriteMethod.js";

.overwriteMethod(ctx, name, fn)

Overwrites an already existing method and provides access to previous function. Must return function to be used for name.

utils.overwriteMethod(chai.Assertion.prototype, 'equal', function (_super) {
    return function (str) {
        var obj = utils.flag(this, 'object');
        if (obj instanceof Foo) {
            new chai.Assertion(obj.value).to.equal(str);
        } else {
            _super.apply(this, arguments);
        }
    }
});

Can also be accessed directly from chai.Assertion.

chai.Assertion.overwriteMethod('foo', fn);

Then can be used as any other assertion.

expect(myFoo).to.equal('bar');

Parameters

ctx

object whose method is to be overwritten

name

of method to overwrite

method

function that returns a function to be used for name