Add special handling of asymmetric matcher objects as keys in Maps.
The previous Map equality code was assuming that the set of keys would be identical between the two Maps. This change adds insertion-order tracking for each key with its corresponding key. If one of the two keys is an asymmetric equality obj, the keys are eq()'d, and if it succeeds, the corresponding values are compared. Otherwise, the "main" key is looked up directly in the other object; this is to prevent similar-looking obj keys with different obj identities from comparing equal. Fixes #1432.
This commit is contained in:
@@ -23,6 +23,22 @@ describe("Anything", function() {
|
||||
expect(anything.asymmetricMatch([1,2,3])).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a Map", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
|
||||
var anything = new jasmineUnderTest.Anything();
|
||||
|
||||
expect(anything.asymmetricMatch(new Map())).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a Set", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
var anything = new jasmineUnderTest.Anything();
|
||||
|
||||
expect(anything.asymmetricMatch(new Set())).toBe(true);
|
||||
});
|
||||
|
||||
it("doesn't match undefined", function() {
|
||||
var anything = new jasmineUnderTest.Anything();
|
||||
|
||||
|
||||
@@ -504,6 +504,14 @@ describe("toEqual", function() {
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("does not report mismatches when comparing Map key to jasmine.anything()", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
|
||||
var actual = new Map([['a', 1]]),
|
||||
expected = new Map([[jasmineUnderTest.anything(), 1]]);
|
||||
expect(compareEquals(actual, expected).pass).toBe(true);
|
||||
});
|
||||
|
||||
function isNotRunningInBrowser() {
|
||||
return typeof document === 'undefined'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user