Add anything matcher to match any value that is neither null or undefined
[finish #58117878] Fix #186
This commit is contained in:
@@ -40,6 +40,7 @@ getJasmineRequireObj = (function (jasmineGlobal) {
|
||||
jRequire.base(j$, jasmineGlobal);
|
||||
j$.util = jRequire.util();
|
||||
j$.Any = jRequire.Any();
|
||||
j$.Anything = jRequire.Anything(j$);
|
||||
j$.CallTracker = jRequire.CallTracker();
|
||||
j$.MockDate = jRequire.MockDate();
|
||||
j$.Clock = jRequire.Clock();
|
||||
@@ -146,6 +147,10 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
||||
return new j$.Any(clazz);
|
||||
};
|
||||
|
||||
j$.anything = function() {
|
||||
return new j$.Anything();
|
||||
};
|
||||
|
||||
j$.objectContaining = function(sample) {
|
||||
return new j$.ObjectContaining(sample);
|
||||
};
|
||||
@@ -967,6 +972,17 @@ getJasmineRequireObj().Any = function() {
|
||||
return Any;
|
||||
};
|
||||
|
||||
getJasmineRequireObj().Anything = function(j$) {
|
||||
|
||||
function Anything() {}
|
||||
|
||||
Anything.prototype.asymmetricMatch = function(other) {
|
||||
return !j$.util.isUndefined(other) && other !== null;
|
||||
};
|
||||
|
||||
return Anything;
|
||||
};
|
||||
|
||||
getJasmineRequireObj().CallTracker = function() {
|
||||
|
||||
function CallTracker() {
|
||||
|
||||
38
spec/core/AnythingSpec.js
Normal file
38
spec/core/AnythingSpec.js
Normal file
@@ -0,0 +1,38 @@
|
||||
describe("Anything", function() {
|
||||
it("matches a string", function() {
|
||||
var anything = new j$.Anything();
|
||||
|
||||
expect(anything.asymmetricMatch('foo')).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a number", function() {
|
||||
var anything = new j$.Anything();
|
||||
|
||||
expect(anything.asymmetricMatch(42)).toBe(true);
|
||||
});
|
||||
|
||||
it("matches an object", function() {
|
||||
var anything = new j$.Anything();
|
||||
|
||||
expect(anything.asymmetricMatch({ foo: 'bar' })).toBe(true);
|
||||
});
|
||||
|
||||
it("matches an array", function() {
|
||||
var anything = new j$.Anything();
|
||||
|
||||
expect(anything.asymmetricMatch([1,2,3])).toBe(true);
|
||||
});
|
||||
|
||||
it("doesn't match undefined", function() {
|
||||
var anything = new j$.Anything();
|
||||
|
||||
expect(anything.asymmetricMatch()).toBe(false);
|
||||
expect(anything.asymmetricMatch(undefined)).toBe(false);
|
||||
});
|
||||
|
||||
it("doesn't match null", function() {
|
||||
var anything = new j$.Anything();
|
||||
|
||||
expect(anything.asymmetricMatch(null)).toBe(false);
|
||||
});
|
||||
});
|
||||
10
src/core/Anything.js
Normal file
10
src/core/Anything.js
Normal file
@@ -0,0 +1,10 @@
|
||||
getJasmineRequireObj().Anything = function(j$) {
|
||||
|
||||
function Anything() {}
|
||||
|
||||
Anything.prototype.asymmetricMatch = function(other) {
|
||||
return !j$.util.isUndefined(other) && other !== null;
|
||||
};
|
||||
|
||||
return Anything;
|
||||
};
|
||||
@@ -45,6 +45,10 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
||||
return new j$.Any(clazz);
|
||||
};
|
||||
|
||||
j$.anything = function() {
|
||||
return new j$.Anything();
|
||||
};
|
||||
|
||||
j$.objectContaining = function(sample) {
|
||||
return new j$.ObjectContaining(sample);
|
||||
};
|
||||
|
||||
@@ -18,6 +18,7 @@ getJasmineRequireObj = (function (jasmineGlobal) {
|
||||
jRequire.base(j$, jasmineGlobal);
|
||||
j$.util = jRequire.util();
|
||||
j$.Any = jRequire.Any();
|
||||
j$.Anything = jRequire.Anything(j$);
|
||||
j$.CallTracker = jRequire.CallTracker();
|
||||
j$.MockDate = jRequire.MockDate();
|
||||
j$.Clock = jRequire.Clock();
|
||||
|
||||
Reference in New Issue
Block a user