File: proxy-guard.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 (79 lines) | stat: -rw-r--r-- 2,981 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"use strict";
const chai = require("chai");
const chaiAsPromised = require("..");

chai.should();
chai.use(chaiAsPromised);

function shouldGuard(fn, msg) {
    fn.should.throw("Invalid Chai property: " + msg);
}

describe("Proxy guard", () => {
    const number = 42;
    const promise = Promise.resolve(42);

    before(function () {
        if (typeof Proxy === "undefined" || typeof Reflect === "undefined" || chai.util.proxify === undefined) {
            /* eslint-disable no-invalid-this */
            this.skip();
            /* eslint-enable no-invalid-this */
        }
    });

    it("should guard against invalid property following `.should`", () => {
        shouldGuard(() => number.should.pizza, "pizza");
    });

    it("should guard against invalid property following overwritten language chain", () => {
        shouldGuard(() => number.should.to.pizza, "pizza");
    });

    it("should guard against invalid property following overwritten property assertion", () => {
        shouldGuard(() => number.should.ok.pizza, "pizza");
    });

    it("should guard against invalid property following uncalled overwritten method assertion", () => {
        shouldGuard(() => number.should.equal.pizza, "equal.pizza. See docs");
    });

    it("should guard against invalid property following called overwritten method assertion", () => {
        shouldGuard(() => number.should.equal(number).pizza, "pizza");
    });

    it("should guard against invalid property following uncalled overwritten chainable method assertion", () => {
        shouldGuard(() => number.should.a.pizza, "pizza");
    });

    it("should guard against invalid property following called overwritten chainable method assertion", () => {
        shouldGuard(() => number.should.a("number").pizza, "pizza");
    });

    it("should guard against invalid property following `.eventually`", () => {
        shouldGuard(() => promise.should.eventually.pizza, "pizza");
    });

    it("should guard against invalid property following `.fulfilled`", () => {
        shouldGuard(() => promise.should.fulfilled.pizza, "pizza");
    });

    it("should guard against invalid property following `.rejected`", () => {
        shouldGuard(() => promise.should.rejected.pizza, "pizza");
    });

    it("should guard against invalid property following called `.rejectedWith`", () => {
        shouldGuard(() => promise.should.rejectedWith(42).pizza, "pizza");
    });

    it("should guard against invalid property following uncalled `.rejectedWith`", () => {
        shouldGuard(() => promise.should.rejectedWith.pizza, "rejectedWith.pizza. See docs");
    });

    it("should guard against invalid property following called `.become`", () => {
        shouldGuard(() => promise.should.become(42).pizza, "pizza");
    });

    it("should guard against invalid property following uncalled `.become`", () => {
        shouldGuard(() => promise.should.become.pizza, "become.pizza. See docs");
    });
});