Rename jasmineMatches to asymmetricMatch
- This should be more clear what it is for [finish #82295210]
This commit is contained in:
@@ -936,7 +936,7 @@ getJasmineRequireObj().Any = function() {
|
|||||||
this.expectedObject = expectedObject;
|
this.expectedObject = expectedObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
Any.prototype.jasmineMatches = function(other) {
|
Any.prototype.asymmetricMatch = function(other) {
|
||||||
if (this.expectedObject == String) {
|
if (this.expectedObject == String) {
|
||||||
return typeof other == 'string' || other instanceof String;
|
return typeof other == 'string' || other instanceof String;
|
||||||
}
|
}
|
||||||
@@ -1549,7 +1549,7 @@ getJasmineRequireObj().ObjectContaining = function(j$) {
|
|||||||
this.sample = sample;
|
this.sample = sample;
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectContaining.prototype.jasmineMatches = function(other) {
|
ObjectContaining.prototype.asymmetricMatch = function(other) {
|
||||||
if (typeof(this.sample) !== 'object') { throw new Error('You must provide an object to objectContaining, not \''+this.sample+'\'.'); }
|
if (typeof(this.sample) !== 'object') { throw new Error('You must provide an object to objectContaining, not \''+this.sample+'\'.'); }
|
||||||
|
|
||||||
var hasKey = function(obj, keyName) {
|
var hasKey = function(obj, keyName) {
|
||||||
@@ -2252,15 +2252,15 @@ getJasmineRequireObj().matchersUtil = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (a instanceof j$.Any) {
|
if (a instanceof j$.Any) {
|
||||||
return a.jasmineMatches(b);
|
return a.asymmetricMatch(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b instanceof j$.Any) {
|
if (b instanceof j$.Any) {
|
||||||
return b.jasmineMatches(a);
|
return b.asymmetricMatch(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b instanceof j$.ObjectContaining) {
|
if (b instanceof j$.ObjectContaining) {
|
||||||
return b.jasmineMatches(a);
|
return b.asymmetricMatch(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a instanceof Error && b instanceof Error) {
|
if (a instanceof Error && b instanceof Error) {
|
||||||
|
|||||||
@@ -2,38 +2,38 @@ describe("Any", function() {
|
|||||||
it("matches a string", function() {
|
it("matches a string", function() {
|
||||||
var any = new j$.Any(String);
|
var any = new j$.Any(String);
|
||||||
|
|
||||||
expect(any.jasmineMatches("foo")).toBe(true);
|
expect(any.asymmetricMatch("foo")).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches a number", function() {
|
it("matches a number", function() {
|
||||||
var any = new j$.Any(Number);
|
var any = new j$.Any(Number);
|
||||||
|
|
||||||
expect(any.jasmineMatches(1)).toBe(true);
|
expect(any.asymmetricMatch(1)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches a function", function() {
|
it("matches a function", function() {
|
||||||
var any = new j$.Any(Function);
|
var any = new j$.Any(Function);
|
||||||
|
|
||||||
expect(any.jasmineMatches(function(){})).toBe(true);
|
expect(any.asymmetricMatch(function(){})).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches an Object", function() {
|
it("matches an Object", function() {
|
||||||
var any = new j$.Any(Object);
|
var any = new j$.Any(Object);
|
||||||
|
|
||||||
expect(any.jasmineMatches({})).toBe(true);
|
expect(any.asymmetricMatch({})).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches a Boolean", function() {
|
it("matches a Boolean", function() {
|
||||||
var any = new j$.Any(Boolean);
|
var any = new j$.Any(Boolean);
|
||||||
|
|
||||||
expect(any.jasmineMatches(true)).toBe(true);
|
expect(any.asymmetricMatch(true)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches another constructed object", function() {
|
it("matches another constructed object", function() {
|
||||||
var Thing = function() {},
|
var Thing = function() {},
|
||||||
any = new j$.Any(Thing);
|
any = new j$.Any(Thing);
|
||||||
|
|
||||||
expect(any.jasmineMatches(new Thing())).toBe(true);
|
expect(any.asymmetricMatch(new Thing())).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("jasmineToString's itself", function() {
|
it("jasmineToString's itself", function() {
|
||||||
|
|||||||
@@ -3,33 +3,33 @@ describe("ObjectContaining", function() {
|
|||||||
it("matches any actual to an empty object", function() {
|
it("matches any actual to an empty object", function() {
|
||||||
var containing = new j$.ObjectContaining({});
|
var containing = new j$.ObjectContaining({});
|
||||||
|
|
||||||
expect(containing.jasmineMatches("foo")).toBe(true);
|
expect(containing.asymmetricMatch("foo")).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not match an empty object actual", function() {
|
it("does not match an empty object actual", function() {
|
||||||
var containing = new j$.ObjectContaining("foo");
|
var containing = new j$.ObjectContaining("foo");
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
containing.jasmineMatches({})
|
containing.asymmetricMatch({})
|
||||||
}).toThrowError(/not 'foo'/)
|
}).toThrowError(/not 'foo'/)
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches when the key/value pair is present in the actual", function() {
|
it("matches when the key/value pair is present in the actual", function() {
|
||||||
var containing = new j$.ObjectContaining({foo: "fooVal"});
|
var containing = new j$.ObjectContaining({foo: "fooVal"});
|
||||||
|
|
||||||
expect(containing.jasmineMatches({foo: "fooVal", bar: "barVal"})).toBe(true);
|
expect(containing.asymmetricMatch({foo: "fooVal", bar: "barVal"})).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not match when the key/value pair is not present in the actual", function() {
|
it("does not match when the key/value pair is not present in the actual", function() {
|
||||||
var containing = new j$.ObjectContaining({foo: "fooVal"});
|
var containing = new j$.ObjectContaining({foo: "fooVal"});
|
||||||
|
|
||||||
expect(containing.jasmineMatches({bar: "barVal", quux: "quuxVal"})).toBe(false);
|
expect(containing.asymmetricMatch({bar: "barVal", quux: "quuxVal"})).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not match when the key is present but the value is different in the actual", function() {
|
it("does not match when the key is present but the value is different in the actual", function() {
|
||||||
var containing = new j$.ObjectContaining({foo: "other"});
|
var containing = new j$.ObjectContaining({foo: "other"});
|
||||||
|
|
||||||
expect(containing.jasmineMatches({foo: "fooVal", bar: "barVal"})).toBe(false);
|
expect(containing.asymmetricMatch({foo: "fooVal", bar: "barVal"})).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("jasmineToString's itself", function() {
|
it("jasmineToString's itself", function() {
|
||||||
@@ -41,6 +41,6 @@ describe("ObjectContaining", function() {
|
|||||||
it("matches recursively", function() {
|
it("matches recursively", function() {
|
||||||
var containing = new j$.ObjectContaining({one: new j$.ObjectContaining({two: {}})});
|
var containing = new j$.ObjectContaining({one: new j$.ObjectContaining({two: {}})});
|
||||||
|
|
||||||
expect(containing.jasmineMatches({one: {two: {}}})).toBe(true);
|
expect(containing.asymmetricMatch({one: {two: {}}})).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ getJasmineRequireObj().Any = function() {
|
|||||||
this.expectedObject = expectedObject;
|
this.expectedObject = expectedObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
Any.prototype.jasmineMatches = function(other) {
|
Any.prototype.asymmetricMatch = function(other) {
|
||||||
if (this.expectedObject == String) {
|
if (this.expectedObject == String) {
|
||||||
return typeof other == 'string' || other instanceof String;
|
return typeof other == 'string' || other instanceof String;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ getJasmineRequireObj().ObjectContaining = function(j$) {
|
|||||||
this.sample = sample;
|
this.sample = sample;
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectContaining.prototype.jasmineMatches = function(other) {
|
ObjectContaining.prototype.asymmetricMatch = function(other) {
|
||||||
if (typeof(this.sample) !== 'object') { throw new Error('You must provide an object to objectContaining, not \''+this.sample+'\'.'); }
|
if (typeof(this.sample) !== 'object') { throw new Error('You must provide an object to objectContaining, not \''+this.sample+'\'.'); }
|
||||||
|
|
||||||
var hasKey = function(obj, keyName) {
|
var hasKey = function(obj, keyName) {
|
||||||
|
|||||||
@@ -64,15 +64,15 @@ getJasmineRequireObj().matchersUtil = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (a instanceof j$.Any) {
|
if (a instanceof j$.Any) {
|
||||||
return a.jasmineMatches(b);
|
return a.asymmetricMatch(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b instanceof j$.Any) {
|
if (b instanceof j$.Any) {
|
||||||
return b.jasmineMatches(a);
|
return b.asymmetricMatch(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b instanceof j$.ObjectContaining) {
|
if (b instanceof j$.ObjectContaining) {
|
||||||
return b.jasmineMatches(a);
|
return b.asymmetricMatch(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a instanceof Error && b instanceof Error) {
|
if (a instanceof Error && b instanceof Error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user