Added matchers: truthy, falsy, empty and notEmpty
This commit is contained in:
40
spec/core/asymmetric_equality/AsymmetricEqualitySpec.js
Normal file
40
spec/core/asymmetric_equality/AsymmetricEqualitySpec.js
Normal file
@@ -0,0 +1,40 @@
|
||||
describe("Fuzzy Equalities", function() {
|
||||
describe('Truthy/Falsy equalities', function() {
|
||||
it('allows the test to pass', function() {
|
||||
expect({
|
||||
name: "Rex",
|
||||
id: null,
|
||||
description: undefined,
|
||||
age: 42,
|
||||
tags: [],
|
||||
}).toEqual({
|
||||
name: jasmineUnderTest.truthy(),
|
||||
id: jasmineUnderTest.falsy(),
|
||||
description: jasmineUnderTest.falsy(),
|
||||
age: jasmineUnderTest.truthy(),
|
||||
tags: jasmineUnderTest.truthy()
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
if (typeof Set !== 'undefined') {
|
||||
describe('empty/notEmpty equalities', function () {
|
||||
it('allows the test to pass', function () {
|
||||
var tags = new Set(['blue', 'green']);
|
||||
expect({
|
||||
name: "Rex",
|
||||
description: '',
|
||||
age: 42,
|
||||
tags: tags,
|
||||
gps_coord: []
|
||||
}).toEqual({
|
||||
name: jasmineUnderTest.notEmpty(),
|
||||
description: jasmineUnderTest.empty(),
|
||||
age: jasmineUnderTest.truthy(),
|
||||
tags: jasmineUnderTest.notEmpty(),
|
||||
gps_coord: jasmineUnderTest.empty()
|
||||
})
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
39
spec/core/asymmetric_equality/EmptySpec.js
Normal file
39
spec/core/asymmetric_equality/EmptySpec.js
Normal file
@@ -0,0 +1,39 @@
|
||||
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);
|
||||
});
|
||||
|
||||
if (typeof Map !== 'undefined') {
|
||||
it("matches an empty map", function () {
|
||||
var empty = new jasmineUnderTest.Empty();
|
||||
|
||||
expect(empty.asymmetricMatch(new Map())).toBe(true);
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof Set !== 'undefined') {
|
||||
it("matches an empty map", function () {
|
||||
var empty = new jasmineUnderTest.Empty();
|
||||
|
||||
expect(empty.asymmetricMatch(new Set())).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);
|
||||
});
|
||||
});
|
||||
43
spec/core/asymmetric_equality/NotEmptySpec.js
Normal file
43
spec/core/asymmetric_equality/NotEmptySpec.js
Normal file
@@ -0,0 +1,43 @@
|
||||
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);
|
||||
});
|
||||
|
||||
if (typeof Map !== 'undefined') {
|
||||
it("matches a non empty map", function () {
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof Set !== 'undefined') {
|
||||
it("matches a non empty map", function () {
|
||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
||||
var filledSet = new Set([1,2,2,2,2,34]);
|
||||
|
||||
expect(notEmpty.asymmetricMatch(filledSet)).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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user