Added matchers: truthy, falsy, empty and notEmpty
This commit is contained in:
33
src/core/asymmetric_equality/Empty.js
Normal file
33
src/core/asymmetric_equality/Empty.js
Normal file
@@ -0,0 +1,33 @@
|
||||
getJasmineRequireObj().Empty = function (j$) {
|
||||
|
||||
function Empty() {}
|
||||
|
||||
Empty.prototype.asymmetricMatch = function (other) {
|
||||
if (typeof other === 'string') {
|
||||
return other.length === 0;
|
||||
}
|
||||
|
||||
if (other instanceof Array) {
|
||||
return other.length === 0;
|
||||
}
|
||||
|
||||
if (typeof Map !== 'undefined' && other instanceof Map) {
|
||||
return other.size === 0;
|
||||
}
|
||||
|
||||
if (typeof Set !== 'undefined' && other instanceof Set) {
|
||||
return other.size === 0;
|
||||
}
|
||||
|
||||
if (other instanceof Object) {
|
||||
return Object.keys(other).length === 0;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
Empty.prototype.jasmineToString = function () {
|
||||
return '<jasmine.empty>';
|
||||
};
|
||||
|
||||
return Empty;
|
||||
};
|
||||
18
src/core/asymmetric_equality/Falsy.js
Normal file
18
src/core/asymmetric_equality/Falsy.js
Normal file
@@ -0,0 +1,18 @@
|
||||
getJasmineRequireObj().Falsy = function(j$) {
|
||||
|
||||
function Falsy() {}
|
||||
|
||||
Falsy.prototype.asymmetricMatch = function(other) {
|
||||
if (!other) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
Falsy.prototype.jasmineToString = function() {
|
||||
return '<jasmine.falsy>';
|
||||
};
|
||||
|
||||
return Falsy;
|
||||
};
|
||||
34
src/core/asymmetric_equality/NotEmpty.js
Normal file
34
src/core/asymmetric_equality/NotEmpty.js
Normal file
@@ -0,0 +1,34 @@
|
||||
getJasmineRequireObj().NotEmpty = function (j$) {
|
||||
|
||||
function NotEmpty() {}
|
||||
|
||||
NotEmpty.prototype.asymmetricMatch = function (other) {
|
||||
if (typeof other === 'string') {
|
||||
return other.length !== 0;
|
||||
}
|
||||
|
||||
if (other instanceof Array) {
|
||||
return other.length !== 0;
|
||||
}
|
||||
|
||||
if (typeof Map !== 'undefined' && other instanceof Map) {
|
||||
return other.size !== 0;
|
||||
}
|
||||
|
||||
if (typeof Set !== 'undefined' && other instanceof Set) {
|
||||
return other.size !== 0;
|
||||
}
|
||||
|
||||
if (other instanceof Object) {
|
||||
return Object.keys(other).length !== 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
NotEmpty.prototype.jasmineToString = function () {
|
||||
return '<jasmine.notEmpty>';
|
||||
};
|
||||
|
||||
return NotEmpty;
|
||||
};
|
||||
18
src/core/asymmetric_equality/Truthy.js
Normal file
18
src/core/asymmetric_equality/Truthy.js
Normal file
@@ -0,0 +1,18 @@
|
||||
getJasmineRequireObj().Truthy = function(j$) {
|
||||
|
||||
function Truthy() {}
|
||||
|
||||
Truthy.prototype.asymmetricMatch = function(other) {
|
||||
if (other) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
Truthy.prototype.jasmineToString = function() {
|
||||
return '<jasmine.truthy>';
|
||||
};
|
||||
|
||||
return Truthy;
|
||||
};
|
||||
@@ -123,6 +123,38 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
||||
return new j$.Anything();
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
|
||||
* that will succeed if the actual value being compared is `true` or anything truthy.
|
||||
* @name jasmine.truthy
|
||||
* @function
|
||||
*/
|
||||
j$.truthy = function() {return new j$.Truthy();};
|
||||
|
||||
/**
|
||||
* Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
|
||||
* that will succeed if the actual value being compared is `null`, `undefined`, `0`, `false` or anything falsey.
|
||||
* @name jasmine.falsy
|
||||
* @function
|
||||
*/
|
||||
j$.falsy = function() {return new j$.Falsy();};
|
||||
|
||||
/**
|
||||
* Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
|
||||
* that will succeed if the actual value being compared is empty.
|
||||
* @name jasmine.empty
|
||||
* @function
|
||||
*/
|
||||
j$.empty = function() {return new j$.Empty();};
|
||||
|
||||
/**
|
||||
* Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
|
||||
* that will succeed if the actual value being compared is not empty.
|
||||
* @name jasmine.notEmpty
|
||||
* @function
|
||||
*/
|
||||
j$.notEmpty = function() {return new j$.NotEmpty();};
|
||||
|
||||
/**
|
||||
* Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
|
||||
* that will succeed if the actual value being compared contains at least the keys and values.
|
||||
|
||||
@@ -61,6 +61,11 @@ var getJasmineRequireObj = (function (jasmineGlobal) {
|
||||
j$.ObjectPath = jRequire.ObjectPath(j$);
|
||||
j$.GlobalErrors = jRequire.GlobalErrors(j$);
|
||||
|
||||
j$.Truthy = jRequire.Truthy(j$);
|
||||
j$.Falsy = jRequire.Falsy(j$);
|
||||
j$.Empty = jRequire.Empty(j$);
|
||||
j$.NotEmpty = jRequire.NotEmpty(j$);
|
||||
|
||||
j$.matchers = jRequire.requireMatchers(jRequire, j$);
|
||||
|
||||
return j$;
|
||||
|
||||
Reference in New Issue
Block a user