Test cleanup and fixes [s-t]

This commit is contained in:
Angelos Chalaris
2018-06-18 18:37:35 +03:00
parent ba3e684a27
commit 9cf2c4680c
53 changed files with 286 additions and 409 deletions

View File

@ -1,7 +1,6 @@
const expect = require('expect'); const expect = require('expect');
const sample = require('./sample.js'); const sample = require('./sample.js');
test('sample is a Function', () => { test('sample is a Function', () => {
expect(sample).toBeInstanceOf(Function); expect(sample).toBeInstanceOf(Function);
}); });
@ -10,10 +9,8 @@ const sample = require('./sample.js');
expect(arr.includes(sample(arr))).toBeTruthy(); expect(arr.includes(sample(arr))).toBeTruthy();
}); });
test('Works for single-element arrays', () => { test('Works for single-element arrays', () => {
expect(sample([1]), 1).toBe() expect(sample([1])).toBe(1);
}); });
test('Returns undefined for empty array', () => { test('Returns undefined for empty array', () => {
expect(sample([]), undefined).toBe() expect(sample([])).toBe(undefined);
}); });

View File

@ -1,25 +1,22 @@
const expect = require('expect'); const expect = require('expect');
const sampleSize = require('./sampleSize.js'); const sampleSize = require('./sampleSize.js');
test('sampleSize is a Function', () => { test('sampleSize is a Function', () => {
expect(sampleSize).toBeInstanceOf(Function); expect(sampleSize).toBeInstanceOf(Function);
}); });
const arr = [3,7,9,11]; const arr = [3,7,9,11];
test('Returns a single element without n specified', () => { test('Returns a single element without n specified', () => {
expect(sampleSize(arr).length, 1).toBe() expect(sampleSize(arr).length).toBe(1);
}); });
test('Returns a random sample of specified size from an array', () => { test('Returns a random sample of specified size from an array', () => {
expect(sampleSize(arr, 2).every(x => arr.includes(x))).toBeTruthy(); expect(sampleSize(arr, 2).every(x => arr.includes(x))).toBeTruthy();
}); });
test('Returns all elements in an array if n >= length', () => { test('Returns all elements in an array if n >= length', () => {
expect(sampleSize(arr, 5).length, 4).toBe() expect(sampleSize(arr, 5).length).toBe(4)
}); });
test('Returns an empty array if original array is empty', () => { test('Returns an empty array if original array is empty', () => {
expect(sampleSize([], 2), []).toEqual() expect(sampleSize([], 2)).toEqual([]);
}); });
test('Returns an empty array if n = 0', () => { test('Returns an empty array if n = 0', () => {
expect(sampleSize(arr, 0), []).toEqual() expect(sampleSize(arr, 0)).toEqual([]);
}); });

View File

@ -1,10 +1,6 @@
const expect = require('expect'); const expect = require('expect');
const scrollToTop = require('./scrollToTop.js'); const scrollToTop = require('./scrollToTop.js');
test('scrollToTop is a Function', () => { test('scrollToTop is a Function', () => {
expect(scrollToTop).toBeInstanceOf(Function); expect(scrollToTop).toBeInstanceOf(Function);
}); });

View File

@ -1,11 +1,9 @@
const expect = require('expect'); const expect = require('expect');
const sdbm = require('./sdbm.js'); const sdbm = require('./sdbm.js');
test('sdbm is a Function', () => { test('sdbm is a Function', () => {
expect(sdbm).toBeInstanceOf(Function); expect(sdbm).toBeInstanceOf(Function);
}); });
test('Hashes the input string into a whole number.', () => { test('Hashes the input string into a whole number.', () => {
expect(sdbm('name')).toBe(-3521204949) expect(sdbm('name')).toBe(-3521204949);
}); });

View File

@ -1,12 +1,9 @@
const expect = require('expect'); const expect = require('expect');
const serializeCookie = require('./serializeCookie.js'); const serializeCookie = require('./serializeCookie.js');
test('serializeCookie is a Function', () => { test('serializeCookie is a Function', () => {
expect(serializeCookie).toBeInstanceOf(Function); expect(serializeCookie).toBeInstanceOf(Function);
}); });
test('Serializes the cookie', () => { test('Serializes the cookie', () => {
expect(serializeCookie('foo', 'bar'), 'foo=bar').toBe() expect(serializeCookie('foo', 'bar')).toBe('foo=bar');
}); });

View File

@ -1,10 +1,6 @@
const expect = require('expect'); const expect = require('expect');
const setStyle = require('./setStyle.js'); const setStyle = require('./setStyle.js');
test('setStyle is a Function', () => { test('setStyle is a Function', () => {
expect(setStyle).toBeInstanceOf(Function); expect(setStyle).toBeInstanceOf(Function);
}); });

View File

@ -1,7 +1,6 @@
const expect = require('expect'); const expect = require('expect');
const shallowClone = require('./shallowClone.js'); const shallowClone = require('./shallowClone.js');
test('shallowClone is a Function', () => { test('shallowClone is a Function', () => {
expect(shallowClone).toBeInstanceOf(Function); expect(shallowClone).toBeInstanceOf(Function);
}); });
@ -9,7 +8,5 @@ const shallowClone = require('./shallowClone.js');
const b = shallowClone(a); const b = shallowClone(a);
t.notEqual(a, b, 'Shallow cloning works'); t.notEqual(a, b, 'Shallow cloning works');
test('Does not clone deeply', () => { test('Does not clone deeply', () => {
expect(a.obj, b.obj).toBe() expect(a.obj).toBe(b.obj);
}); });

View File

@ -1,10 +1,6 @@
const expect = require('expect'); const expect = require('expect');
const show = require('./show.js'); const show = require('./show.js');
test('show is a Function', () => { test('show is a Function', () => {
expect(show).toBeInstanceOf(Function); expect(show).toBeInstanceOf(Function);
}); });

View File

@ -1,20 +1,19 @@
const expect = require('expect'); const expect = require('expect');
const shuffle = require('./shuffle.js'); const shuffle = require('./shuffle.js');
test('shuffle is a Function', () => { test('shuffle is a Function', () => {
expect(shuffle).toBeInstanceOf(Function); expect(shuffle).toBeInstanceOf(Function);
}); });
const arr = [1,2,3,4,5,6]; const arr = [1,2,3,4,5,6];
t.notEqual(shuffle(arr), arr, 'Shuffles the array'); test('Shuffles the array', () => {
expect(shuffle(arr)).not.toEqual(arr);
});
test('New array contains all original elements', () => { test('New array contains all original elements', () => {
expect(shuffle(arr).every(x => arr.includes(x))).toBeTruthy(); expect(shuffle(arr).every(x => arr.includes(x))).toBeTruthy();
}); });
test('Works for empty arrays', () => { test('Works for empty arrays', () => {
expect(shuffle([]),[]).toEqual() expect(shuffle([])).toEqual([]);
}); });
test('Works for single-element arrays', () => { test('Works for single-element arrays', () => {
expect(shuffle([1]),[1]).toEqual() expect(shuffle([1])).toEqual([1]);
}); });

View File

@ -1,11 +1,9 @@
const expect = require('expect'); const expect = require('expect');
const similarity = require('./similarity.js'); const similarity = require('./similarity.js');
test('similarity is a Function', () => { test('similarity is a Function', () => {
expect(similarity).toBeInstanceOf(Function); expect(similarity).toBeInstanceOf(Function);
}); });
test('Returns an array of elements that appear in both arrays.', () => { test('Returns an array of elements that appear in both arrays.', () => {
expect(similarity([1, 2, 3], [1, 2, 4]), [1).toEqual(2]) expect(similarity([1, 2, 3], [1, 2, 4])).toEqual([1, 2]);
}); });

View File

@ -1,14 +1,12 @@
const expect = require('expect'); const expect = require('expect');
const size = require('./size.js'); const size = require('./size.js');
test('size is a Function', () => { test('size is a Function', () => {
expect(size).toBeInstanceOf(Function); expect(size).toBeInstanceOf(Function);
}); });
test('Get size of arrays, objects or strings.', () => { test('Get size of arrays, objects or strings.', () => {
expect(size([1, 2, 3, 4, 5])).toBe(5) expect(size([1, 2, 3, 4, 5])).toBe(5);
}); });
test('Get size of arrays, objects or strings.', () => { test('Get size of arrays, objects or strings.', () => {
expect(size({ one: 1, two: 2, three: 3 })).toBe(3) expect(size({ one: 1, two: 2, three: 3 })).toBe(3);
}); });

View File

@ -1,13 +1,12 @@
const expect = require('expect'); const expect = require('expect');
const sleep = require('./sleep.js'); const sleep = require('./sleep.js');
test('sleep is a Function', () => { test('sleep is a Function', () => {
expect(sleep).toBeInstanceOf(Function); expect(sleep).toBeInstanceOf(Function);
}); });
test('Works as expected', () => {
async function sleepyWork() { async function sleepyWork() {
await sleep(1000); await sleep(1000);
expect(true).toBeTruthy();
} }
});

View File

@ -1,8 +1,6 @@
const expect = require('expect'); const expect = require('expect');
const smoothScroll = require('./smoothScroll.js'); const smoothScroll = require('./smoothScroll.js');
test('smoothScroll is a Function', () => { test('smoothScroll is a Function', () => {
expect(smoothScroll).toBeInstanceOf(Function); expect(smoothScroll).toBeInstanceOf(Function);
}); });

View File

@ -1,8 +1,6 @@
const expect = require('expect'); const expect = require('expect');
const solveRPN = require('./solveRPN.js'); const solveRPN = require('./solveRPN.js');
test('solveRPN is a Function', () => { test('solveRPN is a Function', () => {
expect(solveRPN).toBeInstanceOf(Function); expect(solveRPN).toBeInstanceOf(Function);
}); });

View File

@ -1,11 +1,9 @@
const expect = require('expect'); const expect = require('expect');
const sortCharactersInString = require('./sortCharactersInString.js'); const sortCharactersInString = require('./sortCharactersInString.js');
test('sortCharactersInString is a Function', () => { test('sortCharactersInString is a Function', () => {
expect(sortCharactersInString).toBeInstanceOf(Function); expect(sortCharactersInString).toBeInstanceOf(Function);
}); });
test('Alphabetically sorts the characters in a string.', () => { test('Alphabetically sorts the characters in a string.', () => {
expect(sortCharactersInString('cabbage')).toBe('aabbceg') expect(sortCharactersInString('cabbage')).toBe('aabbceg');
}); });

View File

@ -1,14 +1,12 @@
const expect = require('expect'); const expect = require('expect');
const sortedIndex = require('./sortedIndex.js'); const sortedIndex = require('./sortedIndex.js');
test('sortedIndex is a Function', () => { test('sortedIndex is a Function', () => {
expect(sortedIndex).toBeInstanceOf(Function); expect(sortedIndex).toBeInstanceOf(Function);
}); });
test('Returns the lowest index at which value should be inserted into array in order to maintain its sort order.', () => { test('Returns the lowest index at which value should be inserted into array in order to maintain its sort order.', () => {
expect(sortedIndex([5, 3, 2, 1], 4)).toBe(1) expect(sortedIndex([5, 3, 2, 1], 4)).toBe(1);
}); });
test('Returns the lowest index at which value should be inserted into array in order to maintain its sort order.', () => { test('Returns the lowest index at which value should be inserted into array in order to maintain its sort order.', () => {
expect(sortedIndex([30, 50], 40)).toBe(1) expect(sortedIndex([30, 50], 40)).toBe(1);
}); });

View File

@ -1,12 +1,9 @@
const expect = require('expect'); const expect = require('expect');
const sortedIndexBy = require('./sortedIndexBy.js'); const sortedIndexBy = require('./sortedIndexBy.js');
test('sortedIndexBy is a Function', () => { test('sortedIndexBy is a Function', () => {
expect(sortedIndexBy).toBeInstanceOf(Function); expect(sortedIndexBy).toBeInstanceOf(Function);
}); });
test('Returns the lowest index to insert the element without messing up the list order', () => { test('Returns the lowest index to insert the element without messing up the list order', () => {
expect(sortedIndexBy([{ x: 4 }, { x: 5 }], { x: 4 }, o => o.x), 0).toBe() expect(sortedIndexBy([{ x: 4 }, { x: 5 }], { x: 4 }, o => o.x)).toBe(0);
}); });

View File

@ -1,12 +1,9 @@
const expect = require('expect'); const expect = require('expect');
const sortedLastIndex = require('./sortedLastIndex.js'); const sortedLastIndex = require('./sortedLastIndex.js');
test('sortedLastIndex is a Function', () => { test('sortedLastIndex is a Function', () => {
expect(sortedLastIndex).toBeInstanceOf(Function); expect(sortedLastIndex).toBeInstanceOf(Function);
}); });
test('Returns the highest index to insert the element without messing up the list order', () => { test('Returns the highest index to insert the element without messing up the list order', () => {
expect(sortedLastIndex([10, 20, 30, 30, 40], 30), 4).toBe() expect(sortedLastIndex([10, 20, 30, 30, 40], 30)).toBe(4);
}); });

View File

@ -1,12 +1,9 @@
const expect = require('expect'); const expect = require('expect');
const sortedLastIndexBy = require('./sortedLastIndexBy.js'); const sortedLastIndexBy = require('./sortedLastIndexBy.js');
test('sortedLastIndexBy is a Function', () => { test('sortedLastIndexBy is a Function', () => {
expect(sortedLastIndexBy).toBeInstanceOf(Function); expect(sortedLastIndexBy).toBeInstanceOf(Function);
}); });
test('Returns the highest index to insert the element without messing up the list order', () => { test('Returns the highest index to insert the element without messing up the list order', () => {
expect(sortedLastIndexBy([{ x: 4 }, { x: 5 }], { x: 4 }, o => o.x), 1).toBe() expect(sortedLastIndexBy([{ x: 4 }, { x: 5 }], { x: 4 }, o => o.x)).toBe(1);
}); });

View File

@ -1,8 +1,6 @@
const expect = require('expect'); const expect = require('expect');
const speechSynthesis = require('./speechSynthesis.js'); const speechSynthesis = require('./speechSynthesis.js');
test('speechSynthesis is a Function', () => { test('speechSynthesis is a Function', () => {
expect(speechSynthesis).toBeInstanceOf(Function); expect(speechSynthesis).toBeInstanceOf(Function);
}); });

View File

@ -1,11 +1,9 @@
const expect = require('expect'); const expect = require('expect');
const splitLines = require('./splitLines.js'); const splitLines = require('./splitLines.js');
test('splitLines is a Function', () => { test('splitLines is a Function', () => {
expect(splitLines).toBeInstanceOf(Function); expect(splitLines).toBeInstanceOf(Function);
}); });
test('Splits a multiline string into an array of lines.', () => { test('Splits a multiline string into an array of lines.', () => {
expect(splitLines('This\nis a\nmultiline\nstring.\n'), ['This', 'is a', 'multiline', 'string.' ).toEqual('']) expect(splitLines('This\nis a\nmultiline\nstring.\n')).toEqual(['This', 'is a', 'multiline', 'string.', '']);
}); });

View File

@ -1,12 +1,10 @@
const expect = require('expect'); const expect = require('expect');
const spreadOver = require('./spreadOver.js'); const spreadOver = require('./spreadOver.js');
test('spreadOver is a Function', () => { test('spreadOver is a Function', () => {
expect(spreadOver).toBeInstanceOf(Function); expect(spreadOver).toBeInstanceOf(Function);
}); });
const arrayMax = spreadOver(Math.max); const arrayMax = spreadOver(Math.max);
test('Takes a variadic function and returns a closure that accepts an array of arguments to map to the inputs of the function.', () => { test('Takes a variadic function and returns a closure that accepts an array of arguments to map to the inputs of the function.', () => {
expect(arrayMax([1, 2, 3])).toBe(3) expect(arrayMax([1, 2, 3])).toBe(3);
}); });

View File

@ -1,15 +1,11 @@
const expect = require('expect'); const expect = require('expect');
const stableSort = require('./stableSort.js'); const stableSort = require('./stableSort.js');
test('stableSort is a Function', () => { test('stableSort is a Function', () => {
expect(stableSort).toBeInstanceOf(Function); expect(stableSort).toBeInstanceOf(Function);
}); });
const arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; const arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const compare = () => 0; const compare = () => 0;
test('Array is properly sorted', () => { test('Array is properly sorted', () => {
expect(stableSort(arr, compare), arr).toEqual() expect(stableSort(arr, compare)).toEqual(arr);
}); });

View File

@ -1,14 +1,12 @@
const expect = require('expect'); const expect = require('expect');
const standardDeviation = require('./standardDeviation.js'); const standardDeviation = require('./standardDeviation.js');
test('standardDeviation is a Function', () => { test('standardDeviation is a Function', () => {
expect(standardDeviation).toBeInstanceOf(Function); expect(standardDeviation).toBeInstanceOf(Function);
}); });
test('Returns the standard deviation of an array of numbers', () => { test('Returns the standard deviation of an array of numbers', () => {
expect(standardDeviation([10, 2, 38, 23, 38, 23, 21])).toBe(13.284434142114991) expect(standardDeviation([10, 2, 38, 23, 38, 23, 21])).toBeCloseTo(13.284434142114991,5);
}); });
test('Returns the standard deviation of an array of numbers', () => { test('Returns the standard deviation of an array of numbers', () => {
expect(standardDeviation([10, 2, 38, 23, 38, 23, 21], true)).toBe(12.29899614287479) expect(standardDeviation([10, 2, 38, 23, 38, 23, 21], true)).toBeCloseTo(12.29899614287479,5);
}); });

View File

@ -1,18 +1,15 @@
const expect = require('expect'); const expect = require('expect');
const stringPermutations = require('./stringPermutations.js'); const stringPermutations = require('./stringPermutations.js');
test('stringPermutations is a Function', () => { test('stringPermutations is a Function', () => {
expect(stringPermutations).toBeInstanceOf(Function); expect(stringPermutations).toBeInstanceOf(Function);
}); });
test('Generates all stringPermutations of a string', () => { test('Generates all stringPermutations of a string', () => {
expect(stringPermutations('abc'), ['abc','acb','bac','bca','cab').toEqual('cba']) expect(stringPermutations('abc'), ['abc','acb','bac','bca','cab').toEqual('cba']);
}); });
test('Works for single-letter strings', () => { test('Works for single-letter strings', () => {
expect(stringPermutations('a')).toEqual(['a']) expect(stringPermutations('a')).toEqual(['a']);
}); });
test('Works for empty strings', () => { test('Works for empty strings', () => {
expect(stringPermutations('')).toEqual(['']) expect(stringPermutations('')).toEqual(['']);
}); });

View File

@ -1,12 +1,9 @@
const expect = require('expect'); const expect = require('expect');
const stripHTMLTags = require('./stripHTMLTags.js'); const stripHTMLTags = require('./stripHTMLTags.js');
test('stripHTMLTags is a Function', () => { test('stripHTMLTags is a Function', () => {
expect(stripHTMLTags).toBeInstanceOf(Function); expect(stripHTMLTags).toBeInstanceOf(Function);
}); });
test('Removes HTML tags', () => { test('Removes HTML tags', () => {
expect(stripHTMLTags('<p><em>lorem</em> <strong>ipsum</strong></p><img /><br>'), 'lorem ipsum').toBe() expect(stripHTMLTags('<p><em>lorem</em> <strong>ipsum</strong></p><img /><br>')).toBe('lorem ipsum');
}); });

View File

@ -1,11 +1,9 @@
const expect = require('expect'); const expect = require('expect');
const sum = require('./sum.js'); const sum = require('./sum.js');
test('sum is a Function', () => { test('sum is a Function', () => {
expect(sum).toBeInstanceOf(Function); expect(sum).toBeInstanceOf(Function);
}); });
test('Returns the sum of two or more numbers/arrays.', () => { test('Returns the sum of two or more numbers/arrays.', () => {
expect(sum(...[1, 2, 3, 4])).toBe(10) expect(sum(...[1, 2, 3, 4])).toBe(10);
}); });

View File

@ -1,8 +1,6 @@
const expect = require('expect'); const expect = require('expect');
const sumBy = require('./sumBy.js'); const sumBy = require('./sumBy.js');
test('sumBy is a Function', () => { test('sumBy is a Function', () => {
expect(sumBy).toBeInstanceOf(Function); expect(sumBy).toBeInstanceOf(Function);
}); });

View File

@ -1,17 +1,15 @@
const expect = require('expect'); const expect = require('expect');
const sumPower = require('./sumPower.js'); const sumPower = require('./sumPower.js');
test('sumPower is a Function', () => { test('sumPower is a Function', () => {
expect(sumPower).toBeInstanceOf(Function); expect(sumPower).toBeInstanceOf(Function);
}); });
test('Returns the sum of the powers of all the numbers from start to end', () => { test('Returns the sum of the powers of all the numbers from start to end', () => {
expect(sumPower(10)).toBe(385) expect(sumPower(10)).toBe(385);
}); });
test('Returns the sum of the powers of all the numbers from start to end', () => { test('Returns the sum of the powers of all the numbers from start to end', () => {
expect(sumPower(10, 3)).toBe(3025) expect(sumPower(10, 3)).toBe(3025);
}); });
test('Returns the sum of the powers of all the numbers from start to end', () => { test('Returns the sum of the powers of all the numbers from start to end', () => {
expect(sumPower(10, 3, 5)).toBe(2925) expect(sumPower(10, 3, 5)).toBe(2925);
}); });

View File

@ -1,11 +1,9 @@
const expect = require('expect'); const expect = require('expect');
const symmetricDifference = require('./symmetricDifference.js'); const symmetricDifference = require('./symmetricDifference.js');
test('symmetricDifference is a Function', () => { test('symmetricDifference is a Function', () => {
expect(symmetricDifference).toBeInstanceOf(Function); expect(symmetricDifference).toBeInstanceOf(Function);
}); });
test('Returns the symmetric difference between two arrays.', () => { test('Returns the symmetric difference between two arrays.', () => {
expect(symmetricDifference([1, 2, 3], [1, 2, 4]), [3).toEqual(4]) expect(symmetricDifference([1, 2, 3], [1, 2, 4])).toEqual([3, 4]);
}); });

View File

@ -1,12 +1,9 @@
const expect = require('expect'); const expect = require('expect');
const symmetricDifferenceBy = require('./symmetricDifferenceBy.js'); const symmetricDifferenceBy = require('./symmetricDifferenceBy.js');
test('symmetricDifferenceBy is a Function', () => { test('symmetricDifferenceBy is a Function', () => {
expect(symmetricDifferenceBy).toBeInstanceOf(Function); expect(symmetricDifferenceBy).toBeInstanceOf(Function);
}); });
test('Returns the symmetric difference between two arrays, after applying the provided function to each array element of both', () => { test('Returns the symmetric difference between two arrays, after applying the provided function to each array element of both', () => {
expect(symmetricDifferenceBy([2.1, 1.2], [2.3, 3.4], Math.floor), [ 1.2, 3.4 ]).toEqual() expect(symmetricDifferenceBy([2.1, 1.2], [2.3, 3.4], Math.floor)).toEqual([ 1.2, 3.4 ]);
}); });

View File

@ -1,14 +1,12 @@
const expect = require('expect'); const expect = require('expect');
const symmetricDifferenceWith = require('./symmetricDifferenceWith.js'); const symmetricDifferenceWith = require('./symmetricDifferenceWith.js');
test('symmetricDifferenceWith is a Function', () => { test('symmetricDifferenceWith is a Function', () => {
expect(symmetricDifferenceWith).toBeInstanceOf(Function); expect(symmetricDifferenceWith).toBeInstanceOf(Function);
}); });
t.deepEqual(symmetricDifferenceWith( test('Returns the symmetric difference between two arrays, using a provided function as a comparator', () => {
expect(symmetricDifferenceWith(
[1, 1.2, 1.5, 3, 0], [1, 1.2, 1.5, 3, 0],
[1.9, 3, 0, 3.9], [1.9, 3, 0, 3.9],
(a, b) => Math.round(a) === Math.round(b) (a, b) => Math.round(a) === Math.round(b))).toEqual([1, 1.2, 3.9]);
), [1, 1.2, 3.9], 'Returns the symmetric difference between two arrays, using a provided function as a comparator'); });

View File

@ -1,14 +1,12 @@
const expect = require('expect'); const expect = require('expect');
const tail = require('./tail.js'); const tail = require('./tail.js');
test('tail is a Function', () => { test('tail is a Function', () => {
expect(tail).toBeInstanceOf(Function); expect(tail).toBeInstanceOf(Function);
}); });
test('Returns tail', () => { test('Returns tail', () => {
expect(tail([1, 2, 3]), [2).toEqual(3]) expect(tail([1, 2, 3]), [2).toEqual(3]);
}); });
test('Returns tail', () => { test('Returns tail', () => {
expect(tail([1])).toEqual([1]) expect(tail([1])).toEqual([1]);
}); });

View File

@ -1,7 +1,6 @@
const expect = require('expect'); const expect = require('expect');
const take = require('./take.js'); const take = require('./take.js');
test('take is a Function', () => { test('take is a Function', () => {
expect(take).toBeInstanceOf(Function); expect(take).toBeInstanceOf(Function);
}); });
@ -11,5 +10,3 @@ const take = require('./take.js');
test('Returns an array with n elements removed from the beginning.', () => { test('Returns an array with n elements removed from the beginning.', () => {
expect(take([1, 2, 3], 0)).toEqual([]) expect(take([1, 2, 3], 0)).toEqual([])
}); });

View File

@ -1,14 +1,12 @@
const expect = require('expect'); const expect = require('expect');
const takeRight = require('./takeRight.js'); const takeRight = require('./takeRight.js');
test('takeRight is a Function', () => { test('takeRight is a Function', () => {
expect(takeRight).toBeInstanceOf(Function); expect(takeRight).toBeInstanceOf(Function);
}); });
test('Returns an array with n elements removed from the end', () => { test('Returns an array with n elements removed from the end', () => {
expect(takeRight([1, 2, 3], 2), [2).toEqual(3]) expect(takeRight([1, 2, 3], 2)).toEqual([2, 3]);
}); });
test('Returns an array with n elements removed from the end', () => { test('Returns an array with n elements removed from the end', () => {
expect(takeRight([1, 2, 3])).toEqual([3]) expect(takeRight([1, 2, 3])).toEqual([3])
}); });

View File

@ -1,12 +1,9 @@
const expect = require('expect'); const expect = require('expect');
const takeRightWhile = require('./takeRightWhile.js'); const takeRightWhile = require('./takeRightWhile.js');
test('takeRightWhile is a Function', () => { test('takeRightWhile is a Function', () => {
expect(takeRightWhile).toBeInstanceOf(Function); expect(takeRightWhile).toBeInstanceOf(Function);
}); });
test('Removes elements until the function returns true', () => { test('Removes elements until the function returns true', () => {
expect(takeRightWhile([1, 2, 3, 4], n => n < 3), [3, 4]).toEqual() expect(takeRightWhile([1, 2, 3, 4], n => n < 3)).toEqual([3, 4]);
}); });

View File

@ -1,12 +1,9 @@
const expect = require('expect'); const expect = require('expect');
const takeWhile = require('./takeWhile.js'); const takeWhile = require('./takeWhile.js');
test('takeWhile is a Function', () => { test('takeWhile is a Function', () => {
expect(takeWhile).toBeInstanceOf(Function); expect(takeWhile).toBeInstanceOf(Function);
}); });
test('Removes elements until the function returns true', () => { test('Removes elements until the function returns true', () => {
expect(takeWhile([1, 2, 3, 4], n => n >= 3), [1, 2]).toEqual() expect(takeWhile([1, 2, 3, 4], n => n >= 3)).toEqual([1, 2]);
}); });

View File

@ -1,10 +1,6 @@
const expect = require('expect'); const expect = require('expect');
const throttle = require('./throttle.js'); const throttle = require('./throttle.js');
test('throttle is a Function', () => { test('throttle is a Function', () => {
expect(throttle).toBeInstanceOf(Function); expect(throttle).toBeInstanceOf(Function);
}); });

View File

@ -1,10 +1,6 @@
const expect = require('expect'); const expect = require('expect');
const timeTaken = require('./timeTaken.js'); const timeTaken = require('./timeTaken.js');
test('timeTaken is a Function', () => { test('timeTaken is a Function', () => {
expect(timeTaken).toBeInstanceOf(Function); expect(timeTaken).toBeInstanceOf(Function);
}); });

View File

@ -1,14 +1,11 @@
const expect = require('expect'); const expect = require('expect');
const times = require('./times.js'); const times = require('./times.js');
test('times is a Function', () => { test('times is a Function', () => {
expect(times).toBeInstanceOf(Function); expect(times).toBeInstanceOf(Function);
}); });
var output = ''; var output = '';
times(5, i => (output += i)); times(5, i => (output += i));
test('Runs a function the specified amount of times', () => { test('Runs a function the specified amount of times', () => {
expect(output, '01234').toBe() expect(output).toBe('01234');
}); });

View File

@ -1,32 +1,36 @@
const expect = require('expect'); const expect = require('expect');
const toCamelCase = require('./toCamelCase.js'); const toCamelCase = require('./toCamelCase.js');
test('toCamelCase is a Function', () => { test('toCamelCase is a Function', () => {
expect(toCamelCase).toBeInstanceOf(Function); expect(toCamelCase).toBeInstanceOf(Function);
}); });
test('toCamelCase('some_database_field_name') returns someDatabaseFieldName', () => { test('toCamelCase('some_database_field_name') returns someDatabaseFieldName', () => {
expect(toCamelCase('some_database_field_name')).toBe('someDatabaseFieldName') expect(toCamelCase('some_database_field_name')).toBe('someDatabaseFieldName');
}); });
test('toCamelCase('Some label that needs to be camelized') returns someLabelThatNeedsToBeCamelized', () => { test('toCamelCase('Some label that needs to be camelized') returns someLabelThatNeedsToBeCamelized', () => {
expect(toCamelCase('Some label that needs to be camelized')).toBe('someLabelThatNeedsToBeCamelized') expect(toCamelCase('Some label that needs to be camelized')).toBe('someLabelThatNeedsToBeCamelized');
}); });
test('toCamelCase('some-javascript-property') return someJavascriptProperty', () => { test('toCamelCase('some-javascript-property') return someJavascriptProperty', () => {
expect(toCamelCase('some-javascript-property')).toBe('someJavascriptProperty') expect(toCamelCase('some-javascript-property')).toBe('someJavascriptProperty');
}); });
test('toCamelCase('some-mixed_string with spaces_underscores-and-hyphens') returns someMixedStringWithSpacesUnderscoresAndHyphens', () => { test('toCamelCase('some-mixed_string with spaces_underscores-and-hyphens') returns someMixedStringWithSpacesUnderscoresAndHyphens', () => {
expect(toCamelCase('some-mixed_string with spaces_underscores-and-hyphens')).toBe('someMixedStringWithSpacesUnderscoresAndHyphens') expect(toCamelCase('some-mixed_string with spaces_underscores-and-hyphens')).toBe('someMixedStringWithSpacesUnderscoresAndHyphens');
});
test('toCamelCase() throws a error', () => {
expect(toCamelCase()).toThrow();
});
test('toCamelCase([]) throws a error', () => {
expect(toCamelCase([])).toThrow();
});
test('toCamelCase({}) throws a error', () => {
expect(toCamelCase({})).toThrow();
});
test('toCamelCase(123) throws a error', () => {
expect(toCamelCase(123)).toThrow();
}); });
t.throws(() => toCamelCase(), 'toCamelCase() throws a error');
t.throws(() => toCamelCase([]), 'toCamelCase([]) throws a error');
t.throws(() => toCamelCase({}), 'toCamelCase({}) throws a error');
t.throws(() => toCamelCase(123), 'toCamelCase(123) throws a error');
let start = new Date().getTime(); let start = new Date().getTime();
toCamelCase('some-mixed_string with spaces_underscores-and-hyphens'); toCamelCase('some-mixed_string with spaces_underscores-and-hyphens');
let end = new Date().getTime(); let end = new Date().getTime();
test('toCamelCase(some-mixed_string with spaces_underscores-and-hyphens) takes less than 2s to run', () => { test('toCamelCase(some-mixed_string with spaces_underscores-and-hyphens) takes less than 2s to run', () => {
expect((end - start) < 2000).toBeTruthy(); expect((end - start) < 2000).toBeTruthy();
}); });

View File

@ -1,18 +1,15 @@
const expect = require('expect'); const expect = require('expect');
const toCurrency = require('./toCurrency.js'); const toCurrency = require('./toCurrency.js');
test('toCurrency is a Function', () => { test('toCurrency is a Function', () => {
expect(toCurrency).toBeInstanceOf(Function); expect(toCurrency).toBeInstanceOf(Function);
}); });
test('currency: Euro | currencyLangFormat: Local', () => { test('currency: Euro | currencyLangFormat: Local', () => {
expect(toCurrency(123456.789, 'EUR'), '€ 123,456.79').toBe() expect(toCurrency(123456.789, 'EUR'), '€ 123,456.79').stringMatching(/€\s*123,456.79/g);
}); });
test(' currency: US Dollar | currencyLangFormat: English (United States)', () => { test(' currency: US Dollar | currencyLangFormat: English (United States)', () => {
expect(toCurrency(123456.789, 'USD', 'en-us'), '$123,456.79').toBe() expect(toCurrency(123456.789, 'USD', 'en-us')).stringMatching(/\$\s*123,456.79/g);
}); });
test('currency: Japanese Yen | currencyLangFormat: Local', () => { test('currency: Japanese Yen | currencyLangFormat: Local', () => {
expect(toCurrency(322342436423.2435, 'JPY'), 'JP¥ 322,342,436,423').toBe() expect(toCurrency(322342436423.2435, 'JPY'), 'JP¥ 322,342,436,423').stringMatching(/J*P*¥\s*322,342,436,423/g);
}); });

View File

@ -1,11 +1,9 @@
const expect = require('expect'); const expect = require('expect');
const toDecimalMark = require('./toDecimalMark.js'); const toDecimalMark = require('./toDecimalMark.js');
test('toDecimalMark is a Function', () => { test('toDecimalMark is a Function', () => {
expect(toDecimalMark).toBeInstanceOf(Function); expect(toDecimalMark).toBeInstanceOf(Function);
}); });
test('convert a float-point arithmetic to the Decimal mark form', () => { test('convert a float-point arithmetic to the Decimal mark form', () => {
expect(toDecimalMark(12305030388.9087), "12,305,030).toBe(388.909") expect(toDecimalMark(12305030388.9087)).toBe("12,305,030,388.909");
}); });

View File

@ -1,8 +1,6 @@
const expect = require('expect'); const expect = require('expect');
const toHash = require('./toHash.js'); const toHash = require('./toHash.js');
test('toHash is a Function', () => { test('toHash is a Function', () => {
expect(toHash).toBeInstanceOf(Function); expect(toHash).toBeInstanceOf(Function);
}); });

View File

@ -1,34 +1,36 @@
const expect = require('expect'); const expect = require('expect');
const toKebabCase = require('./toKebabCase.js'); const toKebabCase = require('./toKebabCase.js');
test('toKebabCase is a Function', () => { test('toKebabCase is a Function', () => {
expect(toKebabCase).toBeInstanceOf(Function); expect(toKebabCase).toBeInstanceOf(Function);
}); });
test('toKebabCase('camelCase') returns camel-case', () => { test('toKebabCase(\'camelCase\') returns camel-case', () => {
expect(toKebabCase('camelCase')).toBe('camel-case') expect(toKebabCase('camelCase')).toBe('camel-case');
}); });
test('toKebabCase('some text') returns some-text', () => { test('toKebabCase(\'some text\') returns some-text', () => {
expect(toKebabCase('some text')).toBe('some-text') expect(toKebabCase('some text')).toBe('some-text');
}); });
test('toKebabCase('some-mixed-string With spaces-underscores-and-hyphens') returns some-mixed-string-with-spaces-underscores-and-hyphens', () => { test('toKebabCase(\'some-mixed-string With spaces-underscores-and-hyphens\') returns some-mixed-string-with-spaces-underscores-and-hyphens', () => {
expect(toKebabCase('some-mixed-string With spaces-underscores-and-hyphens')).toBe('some-mixed-string-with-spaces-underscores-and-hyphens') expect(toKebabCase('some-mixed-string With spaces-underscores-and-hyphens')).toBe('some-mixed-string-with-spaces-underscores-and-hyphens');
}); });
test('toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML') returns i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-some-xml-and-html', () => { test('toKebabCase(\'IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML\') returns i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-some-xml-and-html', () => {
expect(toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML')).toBe('i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-some-xml-and-html') expect(toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML')).toBe('i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-some-xml-and-html')
}); });
test('toKebabCase() return undefined', () => { test('toKebabCase() returns undefined', () => {
expect(toKebabCase(), undefined).toBe() expect(toKebabCase()).toBe(undefined)
});
test('toKebabCase([]) throws an erro', () => {
expect(toKebabCase([])).toThrow();
});
test('toKebabCase({}) throws an erro', () => {
expect(toKebabCase({})).toThrow();
});
test('toKebabCase(123) throws an erro', () => {
expect(toKebabCase(123)).toThrow();
}); });
t.throws(() => toKebabCase([]), 'toKebabCase([]) throws an error');
t.throws(() => toKebabCase({}), 'toKebabCase({}) throws an error');
t.throws(() => toKebabCase(123), 'toKebabCase(123) throws an error');
let start = new Date().getTime(); let start = new Date().getTime();
toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML'); toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML');
let end = new Date().getTime(); let end = new Date().getTime();
test('toKebabCase(IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML) takes less than 2s to run', () => { test('toKebabCase(IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML) takes less than 2s to run', () => {
expect((end - start) < 2000).toBeTruthy(); expect((end - start) < 2000).toBeTruthy();
}); });

View File

@ -1,20 +1,18 @@
const expect = require('expect'); const expect = require('expect');
const toOrdinalSuffix = require('./toOrdinalSuffix.js'); const toOrdinalSuffix = require('./toOrdinalSuffix.js');
test('toOrdinalSuffix is a Function', () => { test('toOrdinalSuffix is a Function', () => {
expect(toOrdinalSuffix).toBeInstanceOf(Function); expect(toOrdinalSuffix).toBeInstanceOf(Function);
}); });
test('Adds an ordinal suffix to a number', () => { test('Adds an ordinal suffix to a number', () => {
expect(toOrdinalSuffix('123'), '123rd').toBe() expect(toOrdinalSuffix('123')).toBe('123rd');
}); });
test('Adds an ordinal suffix to a number', () => { test('Adds an ordinal suffix to a number', () => {
expect(toOrdinalSuffix(5), '5th').toBe() expect(toOrdinalSuffix(5)).toBe('5th');
}); });
test('Adds an ordinal suffix to a number', () => { test('Adds an ordinal suffix to a number', () => {
expect(toOrdinalSuffix(1), '1st').toBe() expect(toOrdinalSuffix(1)).toBe('1st');
}); });
test('Adds an ordinal suffix to a number', () => { test('Adds an ordinal suffix to a number', () => {
expect(toOrdinalSuffix(0), '0th').toBe() expect(toOrdinalSuffix(0)).toBe('0th');
}); });

View File

@ -1,7 +1,6 @@
const expect = require('expect'); const expect = require('expect');
const toSafeInteger = require('./toSafeInteger.js'); const toSafeInteger = require('./toSafeInteger.js');
test('toSafeInteger is a Function', () => { test('toSafeInteger is a Function', () => {
expect(toSafeInteger).toBeInstanceOf(Function); expect(toSafeInteger).toBeInstanceOf(Function);
}); });
@ -9,38 +8,35 @@ const toSafeInteger = require('./toSafeInteger.js');
expect(Number(toSafeInteger(3.2))).toBeTruthy(); expect(Number(toSafeInteger(3.2))).toBeTruthy();
}); });
test('Converts a value to a safe integer', () => { test('Converts a value to a safe integer', () => {
expect(toSafeInteger(3.2)).toBe(3) expect(toSafeInteger(3.2)).toBe(3);
}); });
test('toSafeInteger('4.2') returns 4', () => { test('toSafeInteger('4.2') returns 4', () => {
expect(toSafeInteger('4.2')).toBe(4) expect(toSafeInteger('4.2')).toBe(4);
}); });
test('toSafeInteger(4.6) returns 5', () => { test('toSafeInteger(4.6) returns 5', () => {
expect(toSafeInteger(4.6)).toBe(5) expect(toSafeInteger(4.6)).toBe(5);
}); });
test('toSafeInteger([]) returns 0', () => { test('toSafeInteger([]) returns 0', () => {
expect(toSafeInteger([])).toBe(0) expect(toSafeInteger([])).toBe(0);
}); });
test('isNaN(toSafeInteger([1.5, 3124])) is true', () => { test('isNaN(toSafeInteger([1.5, 3124])) is true', () => {
expect(isNaN(toSafeInteger([1.5, 3124]))).toBeTruthy() expect(isNaN(toSafeInteger([1.5, 3124]))).toBeTruthy();
}); });
test('isNaN(toSafeInteger('string')) is true', () => { test('isNaN(toSafeInteger('string')) is true', () => {
expect(isNaN(toSafeInteger('string'))).toBeTruthy() expect(isNaN(toSafeInteger('string'))).toBeTruthy();
}); });
test('isNaN(toSafeInteger({})) is true', () => { test('isNaN(toSafeInteger({})) is true', () => {
expect(isNaN(toSafeInteger({}))).toBeTruthy() expect(isNaN(toSafeInteger({}))).toBeTruthy();
}); });
test('isNaN(toSafeInteger()) is true', () => { test('isNaN(toSafeInteger()) is true', () => {
expect(isNaN(toSafeInteger())).toBeTruthy() expect(isNaN(toSafeInteger())).toBeTruthy();
}); });
test('toSafeInteger(Infinity) returns 9007199254740991', () => { test('toSafeInteger(Infinity) returns 9007199254740991', () => {
expect(toSafeInteger(Infinity)).toBe(9007199254740991) expect(toSafeInteger(Infinity)).toBe(9007199254740991);
}); });
let start = new Date().getTime(); let start = new Date().getTime();
toSafeInteger(3.2); toSafeInteger(3.2);
let end = new Date().getTime(); let end = new Date().getTime();
test('toSafeInteger(3.2) takes less than 2s to run', () => { test('toSafeInteger(3.2) takes less than 2s to run', () => {
expect((end - start) < 2000).toBeTruthy(); expect((end - start) < 2000).toBeTruthy();
}); });

View File

@ -1,34 +1,36 @@
const expect = require('expect'); const expect = require('expect');
const toSnakeCase = require('./toSnakeCase.js'); const toSnakeCase = require('./toSnakeCase.js');
test('toSnakeCase is a Function', () => { test('toSnakeCase is a Function', () => {
expect(toSnakeCase).toBeInstanceOf(Function); expect(toSnakeCase).toBeInstanceOf(Function);
}); });
test('toSnakeCase('camelCase') returns camel_case', () => { test('toSnakeCase('\camelCase\') returns camel_case', () => {
expect(toSnakeCase('camelCase')).toBe('camel_case') expect(toSnakeCase('camelCase')).toBe('camel_case');
}); });
test('toSnakeCase('some text') returns some_text', () => { test('toSnakeCase(\'some text\') returns some_text', () => {
expect(toSnakeCase('some text')).toBe('some_text') expect(toSnakeCase('some text')).toBe('some_text');
}); });
test('toSnakeCase('some-mixed_string With spaces_underscores-and-hyphens') returns some_mixed_string_with_spaces_underscores_and_hyphens', () => { test('toSnakeCase(\'some-mixed_string With spaces_underscores-and-hyphens\') returns some_mixed_string_with_spaces_underscores_and_hyphens', () => {
expect(toSnakeCase('some-mixed_string With spaces_underscores-and-hyphens')).toBe('some_mixed_string_with_spaces_underscores_and_hyphens') expect(toSnakeCase('some-mixed_string With spaces_underscores-and-hyphens')).toBe('some_mixed_string_with_spaces_underscores_and_hyphens');
}); });
test('toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML') returns i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html', () => { test('toSnakeCase(\'IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML\') returns i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html', () => {
expect(toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML')).toBe('i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html') expect(toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML')).toBe('i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html')
}); });
test('toSnakeCase() returns undefined', () => { test('toSnakeCase() returns undefined', () => {
expect(toSnakeCase(), undefined).toBe() expect(toSnakeCase()).toBe(undefined);
});
test('toSnakeCase([]) throws an error', () => {
expect(toSnakeCase([])).toThrow();
});
test('toSnakeCase({}) throws an error', () => {
expect(toSnakeCase({})).toThrow();
});
test('toSnakeCase(123) throws an error', () => {
expect(toSnakeCase(123)).toThrow();
}); });
t.throws(() => toSnakeCase([]), 'toSnakeCase([]) throws an error');
t.throws(() => toSnakeCase({}), 'toSnakeCase({}) throws an error');
t.throws(() => toSnakeCase(123), 'toSnakeCase(123) throws an error');
let start = new Date().getTime(); let start = new Date().getTime();
toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML'); toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML');
let end = new Date().getTime(); let end = new Date().getTime();
test('toSnakeCase(IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML) takes less than 2s to run', () => { test('toSnakeCase(IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML) takes less than 2s to run', () => {
expect((end - start) < 2000).toBeTruthy(); expect((end - start) < 2000).toBeTruthy();
}); });

View File

@ -1,10 +1,6 @@
const expect = require('expect'); const expect = require('expect');
const toggleClass = require('./toggleClass.js'); const toggleClass = require('./toggleClass.js');
test('toggleClass is a Function', () => { test('toggleClass is a Function', () => {
expect(toggleClass).toBeInstanceOf(Function); expect(toggleClass).toBeInstanceOf(Function);
}); });

View File

@ -1,20 +1,17 @@
const expect = require('expect'); const expect = require('expect');
const tomorrow = require('./tomorrow.js'); const tomorrow = require('./tomorrow.js');
test('tomorrow is a Function', () => { test('tomorrow is a Function', () => {
expect(tomorrow).toBeInstanceOf(Function); expect(tomorrow).toBeInstanceOf(Function);
}); });
const t1 = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 1); const t1 = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 1);
const t2 = new Date(tomorrow()); const t2 = new Date(tomorrow());
test('Returns the correct year', () => { test('Returns the correct year', () => {
expect(t1.getFullYear(), t2.getFullYear()).toBe() expect(t1.getFullYear()).toBe(t2.getFullYear());
}); });
test('Returns the correct month', () => { test('Returns the correct month', () => {
expect(t1.getMonth(), t2.getMonth()).toBe() expect(t1.getMonth()).toBe(t2.getMonth());
}); });
test('Returns the correct date', () => { test('Returns the correct date', () => {
expect(t1.getDate(), t2.getDate()).toBe() expect(t1.getDate()).toBe(t2.getDate());
}); });

View File

@ -1,17 +1,14 @@
const expect = require('expect'); const expect = require('expect');
const transform = require('./transform.js'); const transform = require('./transform.js');
test('transform is a Function', () => { test('transform is a Function', () => {
expect(transform).toBeInstanceOf(Function); expect(transform).toBeInstanceOf(Function);
}); });
t.deepEqual(transform( test('Transforms an object', () => {
expect(transform(
{ a: 1, b: 2, c: 1 }, { a: 1, b: 2, c: 1 },
(r, v, k) => { (r, v, k) => {
(r[v] || (r[v] = [])).push(k); (r[v] || (r[v] = [])).push(k);
return r; return r;
}, },{}).toEqual({ '1': ['a', 'c'], '2': ['b'] });
{} });
), { '1': ['a', 'c'], '2': ['b'] }, 'Transforms an object');

View File

@ -1,11 +1,9 @@
const expect = require('expect'); const expect = require('expect');
const truncateString = require('./truncateString.js'); const truncateString = require('./truncateString.js');
test('truncateString is a Function', () => { test('truncateString is a Function', () => {
expect(truncateString).toBeInstanceOf(Function); expect(truncateString).toBeInstanceOf(Function);
}); });
test('Truncates a "boomerang" up to a specified length.', () => { test('Truncates a "boomerang" up to a specified length.', () => {
expect(truncateString('boomerang', 7), 'boom...').toBe() expect(truncateString('boomerang', 7)).toBe('boom...');
}); });

View File

@ -1,11 +1,9 @@
const expect = require('expect'); const expect = require('expect');
const truthCheckCollection = require('./truthCheckCollection.js'); const truthCheckCollection = require('./truthCheckCollection.js');
test('truthCheckCollection is a Function', () => { test('truthCheckCollection is a Function', () => {
expect(truthCheckCollection).toBeInstanceOf(Function); expect(truthCheckCollection).toBeInstanceOf(Function);
}); });
test('second argument is truthy on all elements of a collection', () => { test('second argument is truthy on all elements of a collection', () => {
expect(truthCheckCollection([{ user: 'Tinky-Winky', sex: 'male' }, { user: 'Dipsy', sex: 'male' }], 'sex')).toBe(true) expect(truthCheckCollection([{ user: 'Tinky-Winky', sex: 'male' }, { user: 'Dipsy', sex: 'male' }], 'sex')).toBeTruthy();
}); });