Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

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

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

.overwriteProperty(ctx, name, fn)

Overwrites an already existing property getter and provides access to previous value. Must return function to use as getter.

utils.overwriteProperty(chai.Assertion.prototype, 'ok', function (_super) {
    return function () {
        var obj = utils.flag(this, 'object');
        if (obj instanceof Foo) {
            new chai.Assertion(obj.name).to.equal('bar');
        } else {
            _super.call(this);
        }
    }
});

Can also be accessed directly from chai.Assertion.

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

Then can be used as any other assertion.

expect(myFoo).to.be.ok;

Parameters

ctx

object whose property is to be overwritten

name

of property to overwrite

getter

function that returns a getter function to be used for name