moll / js-must

An assertion library for JavaScript and Node.js with a friendly BDD syntax (awesome.must.be.true()). It ships with many expressive matchers and is test runner and framework agnostic. Follows RFC 2119 with its use of MUST. Good stuff and well tested.
Other
336 stars 35 forks source link

must.throw returns unexpected `actual` value when testing message #63

Open dzek69 opened 7 years ago

dzek69 commented 7 years ago

Consider this code:

const test = () => {
    throw new Error("Hi there");
};
describe("module", () => {
    it("throws correct error", () => {
        test.must.throw(Error, "Hello world");
    });
});

My IDE (PHPStorm 2017.1) can't diff expected and actual values for this, printing:

AssertionError: function test() {
    throw new Error("Hi there");
} must throw "Hello world"
Expected :"Hello world"
Actual   :{}

Actual value seems to be Error object here.

Test case for the bug itself:

const test = () => {
    throw new Error("Hi there");
};

describe("must.throw", () => {
    it("returns correct actual value", () => {
        try {
            test.must.throw(Error, "Hello world");
        }
        catch (e) {
            e.expected.must.equal("Hello world");
            e.actual.must.equal("Hi there");
        }
    });
});

This prints:

AssertionError: {"message":"Hi there"} must equal "Hi there"
Expected :"Hi there"
Actual   :{}