From a00f995c681a693c8117ce4ece96f186892a8d59 Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Sat, 21 Sep 2019 14:18:32 -0700 Subject: [PATCH] Added integration tests for existing matcher interfaces --- .../integration/CustomAsyncMatchersSpec.js | 36 +++++++++++++++++ spec/core/integration/CustomMatchersSpec.js | 40 +++++++++++++++++-- 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/spec/core/integration/CustomAsyncMatchersSpec.js b/spec/core/integration/CustomAsyncMatchersSpec.js index 0849e42a..51ddef34 100644 --- a/spec/core/integration/CustomAsyncMatchersSpec.js +++ b/spec/core/integration/CustomAsyncMatchersSpec.js @@ -75,4 +75,40 @@ describe('Custom Async Matchers (Integration)', function() { env.addReporter({ specDone: specExpectations, jasmineDone: done }); env.execute(); }); + + // TODO: remove this in the next major release. + it("passes the jasmine utility and current equality testers to the matcher factory", function(done) { + jasmine.getEnv().requirePromises(); + + var matcherFactory = function () { + return { + compare: function () { + return Promise.resolve({pass: true}); + } + }; + }, + matcherFactorySpy = jasmine.createSpy("matcherFactorySpy").and.callFake(matcherFactory), + customEqualityFn = function () { + return true; + }; + + env.it("spec with expectation", function() { + env.addCustomEqualityTester(customEqualityFn); + env.addAsyncMatchers({ + toBeReal: matcherFactorySpy + }); + + return env.expectAsync(true).toBeReal(); + }); + + var specExpectations = function() { + expect(matcherFactorySpy).toHaveBeenCalledWith( + jasmine.any(jasmineUnderTest.MatchersUtil), + [customEqualityFn] + ); + }; + + env.addReporter({ specDone: specExpectations, jasmineDone: done }); + env.execute(); + }); }); diff --git a/spec/core/integration/CustomMatchersSpec.js b/spec/core/integration/CustomMatchersSpec.js index 17e66354..4bb0c352 100644 --- a/spec/core/integration/CustomMatchersSpec.js +++ b/spec/core/integration/CustomMatchersSpec.js @@ -81,6 +81,34 @@ describe("Custom Matchers (Integration)", function() { env.execute(); }); + it("supports asymmetric equality testers that take a list of custom equality testers", function(done) { + // TODO: remove this in the next major release. + env.it("spec using custom asymmetric equality tester", function() { + var customEqualityFn = function(a, b) { + if (a === 2 && b === "two") { + return true; + } + }; + var arrayWithFirstElement = function(sample) { + return { + asymmetricMatch: function (actual, customEqualityTesters) { + return jasmineUnderTest.matchersUtil.equals(sample, actual[0], customEqualityTesters); + } + }; + }; + + env.addCustomEqualityTester(customEqualityFn); + env.expect(["two"]).toEqual(arrayWithFirstElement(2)); + }); + + var specExpectations = function(result) { + expect(result.status).toEqual('passed'); + }; + + env.addReporter({ specDone: specExpectations, jasmineDone: done }); + env.execute(); + }); + it("displays an appropriate failure message if a custom equality matcher fails", function(done) { env.it("spec using custom equality matcher", function() { var customEqualityFn = function(a, b) { @@ -175,23 +203,27 @@ describe("Custom Matchers (Integration)", function() { env.execute(); }); - it("passes the jasmine utility and current equality matchers to the expectation factory", function(done) { + // TODO: remove this in the next major release. + it("passes the jasmine utility and current equality testers to the matcher factory", function(done) { var matcherFactory = function() { return { compare: function() { return {pass: true}; }}; }, - argumentSpy = jasmine.createSpy("argument spy").and.returnValue(matcherFactory), + matcherFactorySpy = jasmine.createSpy("matcherFactorySpy").and.callFake(matcherFactory), customEqualityFn = function() { return true; }; env.it("spec with expectation", function() { env.addCustomEqualityTester(customEqualityFn); env.addMatchers({ - toBeReal: argumentSpy + toBeReal: matcherFactorySpy }); env.expect(true).toBeReal(); }); var specExpectations = function() { - expect(argumentSpy).toHaveBeenCalledWith(jasmineUnderTest.matchersUtil, [customEqualityFn]); + expect(matcherFactorySpy).toHaveBeenCalledWith( + jasmine.any(jasmineUnderTest.MatchersUtil), + [customEqualityFn] + ); }; env.addReporter({ specDone: specExpectations, jasmineDone: done });