Add asymmetric equality tester to match a string against a regexp
- Also move the asymmetric testers into their own dir for easier locating. [#58120558] Fix #243
This commit is contained in:
36
src/core/asymmetric_equality/Any.js
Normal file
36
src/core/asymmetric_equality/Any.js
Normal file
@@ -0,0 +1,36 @@
|
||||
getJasmineRequireObj().Any = function() {
|
||||
|
||||
function Any(expectedObject) {
|
||||
this.expectedObject = expectedObject;
|
||||
}
|
||||
|
||||
Any.prototype.asymmetricMatch = function(other) {
|
||||
if (this.expectedObject == String) {
|
||||
return typeof other == 'string' || other instanceof String;
|
||||
}
|
||||
|
||||
if (this.expectedObject == Number) {
|
||||
return typeof other == 'number' || other instanceof Number;
|
||||
}
|
||||
|
||||
if (this.expectedObject == Function) {
|
||||
return typeof other == 'function' || other instanceof Function;
|
||||
}
|
||||
|
||||
if (this.expectedObject == Object) {
|
||||
return typeof other == 'object';
|
||||
}
|
||||
|
||||
if (this.expectedObject == Boolean) {
|
||||
return typeof other == 'boolean';
|
||||
}
|
||||
|
||||
return other instanceof this.expectedObject;
|
||||
};
|
||||
|
||||
Any.prototype.jasmineToString = function() {
|
||||
return '<jasmine.any(' + this.expectedObject + ')>';
|
||||
};
|
||||
|
||||
return Any;
|
||||
};
|
||||
Reference in New Issue
Block a user