From 89306551a0746979724d8b251abcd7089252ed91 Mon Sep 17 00:00:00 2001 From: Zaven Muradyan Date: Tue, 24 Oct 2017 22:39:31 -0700 Subject: [PATCH] Add some unit tests that exercise jasmine.anything() and Map matching. Follow-up to some recent commits that fixed issues around jasmine.anything() matching. This simply adds some extra tests that exercise usage of Symbols with jasmine.anything() and as Map keys. --- spec/core/asymmetric_equality/AnythingSpec.js | 16 ++++++++++ spec/core/matchers/toEqualSpec.js | 30 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/spec/core/asymmetric_equality/AnythingSpec.js b/spec/core/asymmetric_equality/AnythingSpec.js index f248226a..76900993 100644 --- a/spec/core/asymmetric_equality/AnythingSpec.js +++ b/spec/core/asymmetric_equality/AnythingSpec.js @@ -39,6 +39,22 @@ describe("Anything", function() { expect(anything.asymmetricMatch(new Set())).toBe(true); }); + it("matches a TypedArray", function() { + jasmine.getEnv().requireFunctioningTypedArrays(); + + var anything = new jasmineUnderTest.Anything(); + + expect(anything.asymmetricMatch(new Uint32Array([]))).toBe(true); + }); + + it("matches a Symbol", function() { + jasmine.getEnv().requireFunctioningSets(); + + var anything = new jasmineUnderTest.Anything(); + + expect(anything.asymmetricMatch(Symbol())).toBe(true); + }); + it("doesn't match undefined", function() { var anything = new jasmineUnderTest.Anything(); diff --git a/spec/core/matchers/toEqualSpec.js b/spec/core/matchers/toEqualSpec.js index d1605a4f..2c4916bb 100644 --- a/spec/core/matchers/toEqualSpec.js +++ b/spec/core/matchers/toEqualSpec.js @@ -512,6 +512,36 @@ describe("toEqual", function() { expect(compareEquals(actual, expected).pass).toBe(true); }); + it("does not report mismatches when comparing Maps with the same symbol keys", function() { + jasmine.getEnv().requireFunctioningMaps(); + jasmine.getEnv().requireFunctioningSymbols(); + + var key = Symbol(), + actual = new Map([[key, 1]]), + expected = new Map([[key, 1]]); + expect(compareEquals(actual, expected).pass).toBe(true); + }); + + it("reports mismatches between Maps with different symbol keys", function() { + jasmine.getEnv().requireFunctioningMaps(); + jasmine.getEnv().requireFunctioningSymbols(); + + var actual = new Map([[Symbol(), 1]]), + expected = new Map([[Symbol(), 1]]), + message = "Expected Map( [ Symbol(), 1 ] ) to equal Map( [ Symbol(), 1 ] )."; + + expect(compareEquals(actual, expected).message).toBe(message); + }); + + it("does not report mismatches when comparing Map symbol key to jasmine.anything()", function() { + jasmine.getEnv().requireFunctioningMaps(); + jasmine.getEnv().requireFunctioningSymbols(); + + var actual = new Map([[Symbol(), 1]]), + expected = new Map([[jasmineUnderTest.anything(), 1]]); + expect(compareEquals(actual, expected).pass).toBe(true); + }); + function isNotRunningInBrowser() { return typeof document === 'undefined' }