|
|
@ -5,22 +5,22 @@ const chai = require('chai'); |
|
|
|
const assert = chai.assert; |
|
|
|
const expect = chai.expect; |
|
|
|
|
|
|
|
let helpers = require('../lib/helpers'); |
|
|
|
let Helpers = require('../lib/Helpers'); |
|
|
|
|
|
|
|
suite('Helper Module Tests -', () => { |
|
|
|
suite('Type-checking methods -', () => { |
|
|
|
suite('Object wrappers are listed as their native type', () => { |
|
|
|
test('Boolean Wrapper returns \'boolean\' not \'object\'', () => { |
|
|
|
let item = Boolean(true); |
|
|
|
expect(helpers.type(item)).to.deep.equal('boolean'); |
|
|
|
expect(Helpers.type(item)).to.deep.equal('boolean'); |
|
|
|
}); |
|
|
|
test('Number Wrapper returns \'number\' not \'object\'', () => { |
|
|
|
let item = Number(4867); |
|
|
|
expect(helpers.type(item)).to.deep.equal('number'); |
|
|
|
expect(Helpers.type(item)).to.deep.equal('number'); |
|
|
|
}); |
|
|
|
test('String Wrapper returns \'string\' not \'object\'', () => { |
|
|
|
let item = String('Foo'); |
|
|
|
expect(helpers.type(item)).to.deep.equal('string'); |
|
|
|
expect(Helpers.type(item)).to.deep.equal('string'); |
|
|
|
}); |
|
|
|
}); |
|
|
|
suite('is..Method methods exist -', () => { |
|
|
@ -40,7 +40,7 @@ suite('Helper Module Tests -', () => { |
|
|
|
|
|
|
|
types.forEach(type => { |
|
|
|
test(`is${type} method exists`, () => { |
|
|
|
assert.ok(helpers[`is${type}`]); |
|
|
|
assert.ok(Helpers[`is${type}`]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -52,7 +52,7 @@ suite('Helper Module Tests -', () => { |
|
|
|
}; |
|
|
|
Object.keys(trueCases).forEach(desc => { |
|
|
|
test(desc, () => { |
|
|
|
expect(helpers.isScalar(trueCases[desc])).to.be.true; |
|
|
|
expect(Helpers.isScalar(trueCases[desc])).to.be.true; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
@ -62,24 +62,24 @@ suite('Helper Module Tests -', () => { |
|
|
|
}; |
|
|
|
Object.keys(falseCases).forEach(desc => { |
|
|
|
test(desc, () => { |
|
|
|
expect(helpers.isScalar(falseCases[desc])).to.be.false; |
|
|
|
expect(Helpers.isScalar(falseCases[desc])).to.be.false; |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
suite('isInfinity -', () => { |
|
|
|
test('The type of 1/0 is infinity', () => { |
|
|
|
expect(helpers.type(1 / 0)).to.equal('infinity'); |
|
|
|
expect(Helpers.type(1 / 0)).to.equal('infinity'); |
|
|
|
}); |
|
|
|
test('isInfinity is the same as isInfinite', () => { |
|
|
|
expect(helpers.isInfinite(1 / 0)).to.be.true; |
|
|
|
expect(Helpers.isInfinite(1 / 0)).to.be.true; |
|
|
|
}); |
|
|
|
}); |
|
|
|
suite('isNaN -', () => { |
|
|
|
test('The type of 0 / 0 is NaN', () => { |
|
|
|
expect(helpers.type(0 / 0)).to.equal('nan'); |
|
|
|
expect(Helpers.type(0 / 0)).to.equal('nan'); |
|
|
|
}); |
|
|
|
test('isNaN method agrees with type', () => { |
|
|
|
expect(helpers.isNaN(0 / 0)).to.be.true; |
|
|
|
expect(Helpers.isNaN(0 / 0)).to.be.true; |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -89,7 +89,7 @@ suite('Helper Module Tests -', () => { |
|
|
|
let orig = [' x y ', 'z ', ' q']; |
|
|
|
let ret = ['x y', 'z', 'q']; |
|
|
|
|
|
|
|
expect(orig.map(helpers.stringTrim)).to.be.deep.equal(ret); |
|
|
|
expect(orig.map(Helpers.stringTrim)).to.be.deep.equal(ret); |
|
|
|
}); |
|
|
|
}); |
|
|
|
suite('arrayPluck -', () => { |
|
|
@ -106,13 +106,13 @@ suite('Helper Module Tests -', () => { |
|
|
|
]; |
|
|
|
|
|
|
|
test('Finding members in all objects', () => { |
|
|
|
expect(helpers.arrayPluck(orig, 'foo')).to.be.deep.equal([1, 2, 3]); |
|
|
|
expect(Helpers.arrayPluck(orig, 'foo')).to.be.deep.equal([1, 2, 3]); |
|
|
|
}); |
|
|
|
test('Some members are missing in some objects', () => { |
|
|
|
expect(helpers.arrayPluck(orig, 'bar')).to.be.deep.equal([10, 15]); |
|
|
|
expect(Helpers.arrayPluck(orig, 'bar')).to.be.deep.equal([10, 15]); |
|
|
|
}); |
|
|
|
test('Empty case', () => { |
|
|
|
expect(helpers.arrayPluck([], 'apple')).to.be.deep.equal([]); |
|
|
|
expect(Helpers.arrayPluck([], 'apple')).to.be.deep.equal([]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
suite('regexInArray -', () => { |
|
|
@ -133,25 +133,25 @@ suite('Helper Module Tests -', () => { |
|
|
|
Object.keys(boolCase).forEach(desc => { |
|
|
|
test(desc, () => { |
|
|
|
if (i) { |
|
|
|
expect(helpers.regexInArray(orig, boolCase[desc])).to.be.true; |
|
|
|
expect(Helpers.regexInArray(orig, boolCase[desc])).to.be.true; |
|
|
|
} else { |
|
|
|
expect(helpers.regexInArray(orig, boolCase[desc])).to.be.false; |
|
|
|
expect(Helpers.regexInArray(orig, boolCase[desc])).to.be.false; |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
test('First argument is not an array', () => { |
|
|
|
expect(helpers.regexInArray(5, /5/)).to.be.false; |
|
|
|
expect(Helpers.regexInArray(5, /5/)).to.be.false; |
|
|
|
}); |
|
|
|
test('Array is empty', () => { |
|
|
|
expect(helpers.regexInArray([], /.*/)).to.be.false; |
|
|
|
expect(Helpers.regexInArray([], /.*/)).to.be.false; |
|
|
|
}); |
|
|
|
}); |
|
|
|
suite('upperCaseFirst -', () => { |
|
|
|
test('Capitalizes only the first letter of the string', () => { |
|
|
|
expect(helpers.upperCaseFirst('foobar')).to.equal('Foobar'); |
|
|
|
expect(helpers.upperCaseFirst('FOOBAR')).to.equal('FOOBAR'); |
|
|
|
expect(Helpers.upperCaseFirst('foobar')).to.equal('Foobar'); |
|
|
|
expect(Helpers.upperCaseFirst('FOOBAR')).to.equal('FOOBAR'); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|