Merge branch 'master' of https://github.com/sjolicoeur/jasmine into sjolicoeur-master
- Merges #1460 from @sjolicoeur
This commit is contained in:
@@ -85,6 +85,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$;
|
||||
@@ -282,6 +287,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.
|
||||
@@ -1723,6 +1760,74 @@ getJasmineRequireObj().ArrayWithExactContents = function(j$) {
|
||||
return ArrayWithExactContents;
|
||||
};
|
||||
|
||||
getJasmineRequireObj().Empty = function (j$) {
|
||||
|
||||
function Empty() {}
|
||||
|
||||
Empty.prototype.asymmetricMatch = function (other) {
|
||||
if (j$.isString_(other) || j$.isArray_(other) || j$.isTypedArray_(other)) {
|
||||
return other.length === 0;
|
||||
}
|
||||
|
||||
if (j$.isMap(other) || j$.isSet(other)) {
|
||||
return other.size === 0;
|
||||
}
|
||||
|
||||
if (j$.isObject_(other)) {
|
||||
return Object.keys(other).length === 0;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
Empty.prototype.jasmineToString = function () {
|
||||
return '<jasmine.empty>';
|
||||
};
|
||||
|
||||
return Empty;
|
||||
};
|
||||
|
||||
getJasmineRequireObj().Falsy = function(j$) {
|
||||
|
||||
function Falsy() {}
|
||||
|
||||
Falsy.prototype.asymmetricMatch = function(other) {
|
||||
return !other;
|
||||
};
|
||||
|
||||
Falsy.prototype.jasmineToString = function() {
|
||||
return '<jasmine.falsy>';
|
||||
};
|
||||
|
||||
return Falsy;
|
||||
};
|
||||
|
||||
getJasmineRequireObj().NotEmpty = function (j$) {
|
||||
|
||||
function NotEmpty() {}
|
||||
|
||||
NotEmpty.prototype.asymmetricMatch = function (other) {
|
||||
if (j$.isString_(other) || j$.isArray_(other) || j$.isTypedArray_(other)) {
|
||||
return other.length !== 0;
|
||||
}
|
||||
|
||||
if (j$.isMap(other) || j$.isSet(other)) {
|
||||
return other.size !== 0;
|
||||
}
|
||||
|
||||
if (j$.isObject_(other)) {
|
||||
return Object.keys(other).length !== 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
NotEmpty.prototype.jasmineToString = function () {
|
||||
return '<jasmine.notEmpty>';
|
||||
};
|
||||
|
||||
return NotEmpty;
|
||||
};
|
||||
|
||||
getJasmineRequireObj().ObjectContaining = function(j$) {
|
||||
|
||||
function ObjectContaining(sample) {
|
||||
@@ -1794,6 +1899,21 @@ getJasmineRequireObj().StringMatching = function(j$) {
|
||||
return StringMatching;
|
||||
};
|
||||
|
||||
getJasmineRequireObj().Truthy = function(j$) {
|
||||
|
||||
function Truthy() {}
|
||||
|
||||
Truthy.prototype.asymmetricMatch = function(other) {
|
||||
return !!other;
|
||||
};
|
||||
|
||||
Truthy.prototype.jasmineToString = function() {
|
||||
return '<jasmine.truthy>';
|
||||
};
|
||||
|
||||
return Truthy;
|
||||
};
|
||||
|
||||
getJasmineRequireObj().CallTracker = function(j$) {
|
||||
|
||||
/**
|
||||
|
||||
44
spec/core/asymmetric_equality/EmptySpec.js
Normal file
44
spec/core/asymmetric_equality/EmptySpec.js
Normal file
@@ -0,0 +1,44 @@
|
||||
describe("Empty", function () {
|
||||
it("matches an empty object", function () {
|
||||
var empty = new jasmineUnderTest.Empty();
|
||||
|
||||
expect(empty.asymmetricMatch({})).toBe(true);
|
||||
expect(empty.asymmetricMatch({undefined: false})).toBe(false);
|
||||
});
|
||||
|
||||
it("matches an empty array", function () {
|
||||
var empty = new jasmineUnderTest.Empty();
|
||||
|
||||
expect(empty.asymmetricMatch([])).toBe(true);
|
||||
expect(empty.asymmetricMatch([1, 12, 3])).toBe(false);
|
||||
});
|
||||
|
||||
it("matches an empty string", function () {
|
||||
var empty = new jasmineUnderTest.Empty();
|
||||
|
||||
expect(empty.asymmetricMatch("")).toBe(true);
|
||||
expect(empty.asymmetricMatch('')).toBe(true);
|
||||
expect(empty.asymmetricMatch('12312')).toBe(false);
|
||||
});
|
||||
|
||||
it("matches an empty map", function () {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var empty = new jasmineUnderTest.Empty();
|
||||
|
||||
expect(empty.asymmetricMatch(new Map())).toBe(true);
|
||||
});
|
||||
|
||||
it("matches an empty map", function () {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
var empty = new jasmineUnderTest.Empty();
|
||||
|
||||
expect(empty.asymmetricMatch(new Set())).toBe(true);
|
||||
});
|
||||
|
||||
it("matches an empty typed array", function() {
|
||||
jasmine.getEnv().requireFunctioningTypedArrays();
|
||||
var empty = new jasmineUnderTest.Empty();
|
||||
|
||||
expect(empty.asymmetricMatch(new Int16Array())).toBe(true);
|
||||
});
|
||||
});
|
||||
38
spec/core/asymmetric_equality/FalsySpec.js
Normal file
38
spec/core/asymmetric_equality/FalsySpec.js
Normal file
@@ -0,0 +1,38 @@
|
||||
describe("Falsy", function() {
|
||||
it("is true for an empty string", function() {
|
||||
var falsy = new jasmineUnderTest.Falsy();
|
||||
|
||||
expect(falsy.asymmetricMatch("")).toBe(true);
|
||||
expect(falsy.asymmetricMatch('')).toBe(true);
|
||||
expect(falsy.asymmetricMatch('asdasdad')).toBe(false);
|
||||
});
|
||||
|
||||
it("is false for a number that is 0", function() {
|
||||
var falsy = new jasmineUnderTest.Falsy(Number);
|
||||
|
||||
expect(falsy.asymmetricMatch(1)).toBe(false);
|
||||
expect(falsy.asymmetricMatch(0)).toBe(true);
|
||||
expect(falsy.asymmetricMatch(-23)).toBe(false);
|
||||
expect(falsy.asymmetricMatch(-3.1)).toBe(false);
|
||||
});
|
||||
|
||||
it("is true for a null or undefined", function() {
|
||||
var falsy = new jasmineUnderTest.Falsy(Function);
|
||||
|
||||
expect(falsy.asymmetricMatch(null)).toBe(true);
|
||||
expect(falsy.asymmetricMatch(undefined )).toBe(true);
|
||||
});
|
||||
|
||||
it("is true for NaN", function() {
|
||||
var falsy = new jasmineUnderTest.Falsy(Object);
|
||||
|
||||
expect(falsy.asymmetricMatch(NaN)).toBe(true);
|
||||
});
|
||||
|
||||
it("is true for a false Boolean", function() {
|
||||
var falsy = new jasmineUnderTest.Falsy(Boolean);
|
||||
|
||||
expect(falsy.asymmetricMatch(false)).toBe(true);
|
||||
expect(falsy.asymmetricMatch(true)).toBe(false);
|
||||
});
|
||||
});
|
||||
48
spec/core/asymmetric_equality/NotEmptySpec.js
Normal file
48
spec/core/asymmetric_equality/NotEmptySpec.js
Normal file
@@ -0,0 +1,48 @@
|
||||
describe("NotEmpty", function () {
|
||||
it("matches a non empty object", function () {
|
||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
||||
|
||||
expect(notEmpty.asymmetricMatch({undefined: false})).toBe(true);
|
||||
expect(notEmpty.asymmetricMatch({})).toBe(false);
|
||||
});
|
||||
|
||||
it("matches a non empty array", function () {
|
||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
||||
|
||||
expect(notEmpty.asymmetricMatch([1, 12, 3])).toBe(true);
|
||||
expect(notEmpty.asymmetricMatch([])).toBe(false);
|
||||
});
|
||||
|
||||
it("matches a non empty string", function () {
|
||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
||||
|
||||
expect(notEmpty.asymmetricMatch('12312')).toBe(true);
|
||||
expect(notEmpty.asymmetricMatch("")).toBe(false);
|
||||
expect(notEmpty.asymmetricMatch('')).toBe(false);
|
||||
});
|
||||
|
||||
it("matches a non empty map", function () {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
||||
var fullMap = new Map([['one',1]]);
|
||||
var emptyMap = new Map();
|
||||
|
||||
expect(notEmpty.asymmetricMatch(fullMap)).toBe(true);
|
||||
expect(notEmpty.asymmetricMatch(emptyMap)).toBe(false);
|
||||
});
|
||||
|
||||
it("matches a non empty map", function () {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
||||
var filledSet = new Set([1,2,2,2,2,34]);
|
||||
|
||||
expect(notEmpty.asymmetricMatch(filledSet)).toBe(true);
|
||||
});
|
||||
|
||||
it("matches an empty typed array", function() {
|
||||
jasmine.getEnv().requireFunctioningTypedArrays();
|
||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
||||
|
||||
expect(notEmpty.asymmetricMatch(new Int16Array([1,2,3]))).toBe(true);
|
||||
});
|
||||
});
|
||||
63
spec/core/asymmetric_equality/TruthySpec.js
Normal file
63
spec/core/asymmetric_equality/TruthySpec.js
Normal file
@@ -0,0 +1,63 @@
|
||||
describe("Truthy", function () {
|
||||
it("is true for a non empty string", function () {
|
||||
var truthy = new jasmineUnderTest.Truthy();
|
||||
|
||||
expect(truthy.asymmetricMatch("foo")).toBe(true);
|
||||
expect(truthy.asymmetricMatch("")).toBe(false);
|
||||
});
|
||||
|
||||
it("is true for a number that is not 0", function () {
|
||||
var truthy = new jasmineUnderTest.Truthy();
|
||||
|
||||
expect(truthy.asymmetricMatch(1)).toBe(true);
|
||||
expect(truthy.asymmetricMatch(0)).toBe(false);
|
||||
expect(truthy.asymmetricMatch(-23)).toBe(true);
|
||||
expect(truthy.asymmetricMatch(-3.1)).toBe(true);
|
||||
});
|
||||
|
||||
it("is true for a function", function () {
|
||||
var truthy = new jasmineUnderTest.Truthy();
|
||||
|
||||
expect(truthy.asymmetricMatch(function () {
|
||||
})).toBe(true);
|
||||
});
|
||||
|
||||
it("is true for an Object", function () {
|
||||
var truthy = new jasmineUnderTest.Truthy();
|
||||
|
||||
expect(truthy.asymmetricMatch({})).toBe(true);
|
||||
});
|
||||
|
||||
it("is true for a truthful Boolean", function () {
|
||||
var truthy = new jasmineUnderTest.Truthy();
|
||||
|
||||
expect(truthy.asymmetricMatch(true)).toBe(true);
|
||||
expect(truthy.asymmetricMatch(false)).toBe(false);
|
||||
});
|
||||
|
||||
it("is true for an empty object", function () {
|
||||
var truthy = new jasmineUnderTest.Truthy();
|
||||
|
||||
expect(truthy.asymmetricMatch({})).toBe(true);
|
||||
});
|
||||
|
||||
it("is true for an empty array", function () {
|
||||
var truthy = new jasmineUnderTest.Truthy();
|
||||
|
||||
expect(truthy.asymmetricMatch([])).toBe(true);
|
||||
});
|
||||
|
||||
it("is true for a date", function () {
|
||||
var truthy = new jasmineUnderTest.Truthy();
|
||||
|
||||
expect(truthy.asymmetricMatch(new Date())).toBe(true);
|
||||
});
|
||||
|
||||
it("is true for a infiniti", function () {
|
||||
var truthy = new jasmineUnderTest.Truthy();
|
||||
|
||||
expect(truthy.asymmetricMatch(Infinity)).toBe(true);
|
||||
expect(truthy.asymmetricMatch(-Infinity)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
25
src/core/asymmetric_equality/Empty.js
Normal file
25
src/core/asymmetric_equality/Empty.js
Normal file
@@ -0,0 +1,25 @@
|
||||
getJasmineRequireObj().Empty = function (j$) {
|
||||
|
||||
function Empty() {}
|
||||
|
||||
Empty.prototype.asymmetricMatch = function (other) {
|
||||
if (j$.isString_(other) || j$.isArray_(other) || j$.isTypedArray_(other)) {
|
||||
return other.length === 0;
|
||||
}
|
||||
|
||||
if (j$.isMap(other) || j$.isSet(other)) {
|
||||
return other.size === 0;
|
||||
}
|
||||
|
||||
if (j$.isObject_(other)) {
|
||||
return Object.keys(other).length === 0;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
Empty.prototype.jasmineToString = function () {
|
||||
return '<jasmine.empty>';
|
||||
};
|
||||
|
||||
return Empty;
|
||||
};
|
||||
14
src/core/asymmetric_equality/Falsy.js
Normal file
14
src/core/asymmetric_equality/Falsy.js
Normal file
@@ -0,0 +1,14 @@
|
||||
getJasmineRequireObj().Falsy = function(j$) {
|
||||
|
||||
function Falsy() {}
|
||||
|
||||
Falsy.prototype.asymmetricMatch = function(other) {
|
||||
return !other;
|
||||
};
|
||||
|
||||
Falsy.prototype.jasmineToString = function() {
|
||||
return '<jasmine.falsy>';
|
||||
};
|
||||
|
||||
return Falsy;
|
||||
};
|
||||
26
src/core/asymmetric_equality/NotEmpty.js
Normal file
26
src/core/asymmetric_equality/NotEmpty.js
Normal file
@@ -0,0 +1,26 @@
|
||||
getJasmineRequireObj().NotEmpty = function (j$) {
|
||||
|
||||
function NotEmpty() {}
|
||||
|
||||
NotEmpty.prototype.asymmetricMatch = function (other) {
|
||||
if (j$.isString_(other) || j$.isArray_(other) || j$.isTypedArray_(other)) {
|
||||
return other.length !== 0;
|
||||
}
|
||||
|
||||
if (j$.isMap(other) || j$.isSet(other)) {
|
||||
return other.size !== 0;
|
||||
}
|
||||
|
||||
if (j$.isObject_(other)) {
|
||||
return Object.keys(other).length !== 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
NotEmpty.prototype.jasmineToString = function () {
|
||||
return '<jasmine.notEmpty>';
|
||||
};
|
||||
|
||||
return NotEmpty;
|
||||
};
|
||||
14
src/core/asymmetric_equality/Truthy.js
Normal file
14
src/core/asymmetric_equality/Truthy.js
Normal file
@@ -0,0 +1,14 @@
|
||||
getJasmineRequireObj().Truthy = function(j$) {
|
||||
|
||||
function Truthy() {}
|
||||
|
||||
Truthy.prototype.asymmetricMatch = function(other) {
|
||||
return !!other;
|
||||
};
|
||||
|
||||
Truthy.prototype.jasmineToString = function() {
|
||||
return '<jasmine.truthy>';
|
||||
};
|
||||
|
||||
return Truthy;
|
||||
};
|
||||
@@ -148,6 +148,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.
|
||||
|
||||
@@ -63,6 +63,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