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

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

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

.addChainableMethod(ctx, name, method, chainingBehavior)

Adds a method to an object, such that the method can also be chained.

utils.addChainableMethod(chai.Assertion.prototype, 'foo', function (str) {
    var obj = utils.flag(this, 'object');
    new chai.Assertion(obj).to.be.equal(str);
});

Can also be accessed directly from chai.Assertion.

chai.Assertion.addChainableMethod('foo', fn, chainingBehavior);

The result can then be used as both a method assertion, executing both method and chainingBehavior, or as a language chain, which only executes chainingBehavior.

expect(fooStr).to.be.foo('bar');
expect(fooStr).to.be.foo.equal('foo');

Parameters

ctx

object to which the method is added

name

of method to add

method

function to be used for name, when called

chainingBehavior

function to be called every time the property is accessed