File: configurable-asserter-args.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 (40 lines) | stat: -rw-r--r-- 1,441 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
"use strict";
require("./support/setup.js");
const chaiAsPromised = require("..");
const originalTransformAsserterArgs = require("..").transformAsserterArgs;

describe("Configuring the way in which asserter arguments are transformed", () => {
    beforeEach(() => {
        chaiAsPromised.transformAsserterArgs = Promise.all.bind(Promise);
    });

    afterEach(() => {
        chaiAsPromised.transformAsserterArgs = originalTransformAsserterArgs;
    });

    it("should override transformAsserterArgs and allow to compare promises", () => {
        const value = "test it";

        return Promise.resolve(value).should.eventually.equal(Promise.resolve(value));
    });

    it("should override transformAsserterArgs and wait until all promises are resolved", () => {
        return Promise.resolve(5).should.eventually.be.within(Promise.resolve(3), Promise.resolve(6));
    });

    it("should not invoke transformAsserterArgs for chai properties", () => {
        chaiAsPromised.transformAsserterArgs = () => {
            throw new Error("transformAsserterArgs should not be called for chai properties");
        };

        return Promise.resolve(true).should.eventually.be.true;
    });

    it("should transform asserter args", () => {
        chaiAsPromised.transformAsserterArgs = args => {
            return Array.from(args).map(x => x + 1);
        };

        return Promise.resolve(3).should.eventually.equal(2);
    });
});