File: chainable-methods-compat.js

package info (click to toggle)
node-chai-as-promised 7.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 244 kB
  • sloc: makefile: 2; sh: 1
file content (44 lines) | stat: -rw-r--r-- 1,044 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"use strict";
const chai = require("chai");
const chaiAsPromised = require("..");
const expect = chai.expect;

function newMethod() {
    // Do nothing
}

function newMethodChain() {
    /* eslint-disable no-invalid-this */
    return this.assert(this._obj.__property === true);
    /* eslint-enable no-invalid-this */
}

function makeFunction() {
    function fn() {
        // Do nothing
    }
    fn.__property = true;
    return fn;
}

chai.use(ctx => {
    ctx.Assertion.addChainableMethod("newMethod", newMethod, newMethodChain);
});

describe("New method `newMethod` added to chai", () => {
    describe("before executing chai.use(chaiAsPromised)", () => {
        it("should work", () => {
            expect(makeFunction()).to.have.been.newMethod();
        });
    });

    describe("after executing chai.use(chaiAsPromised)", () => {
        before(() => {
            chai.use(chaiAsPromised);
        });

        it("should still work", () => {
            expect(makeFunction()).to.have.been.newMethod();
        });
    });
});