From 25d9a396aa3fcd98c2669d86b152d1749953103d Mon Sep 17 00:00:00 2001 From: Jared Deckard Date: Fri, 24 Mar 2017 14:07:23 -0500 Subject: [PATCH] Test that custom matchers can supply custom errors --- spec/core/ExpectationSpec.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/spec/core/ExpectationSpec.js b/spec/core/ExpectationSpec.js index 18cb3921..f41251b9 100644 --- a/spec/core/ExpectationSpec.js +++ b/spec/core/ExpectationSpec.js @@ -384,6 +384,42 @@ describe("Expectation", function() { message: "I'm a custom message" }); }); + + it("reports a custom error message to the spec", function() { + var customError = new Error("I am a custom error"); + var matchers = { + toFoo: function() { + return { + compare: function() { + return { + pass: false, + message: "I am a custom message", + error: customError + }; + } + }; + } + }, + addExpectationResult = jasmine.createSpy("addExpectationResult"), + expectation; + + expectation = new jasmineUnderTest.Expectation({ + actual: "an actual", + customMatchers: matchers, + addExpectationResult: addExpectationResult + }); + + expectation.toFoo("hello"); + + expect(addExpectationResult).toHaveBeenCalledWith(false, { + matcherName: "toFoo", + passed: false, + expected: "hello", + actual: "an actual", + message: "I am a custom message", + error: customError + }); + }); });