This commit is contained in:
Angelos Chalaris
2018-11-10 14:48:56 +02:00
parent b030bc4ca6
commit 4fd8f7bf2e
30 changed files with 93 additions and 9225 deletions

View File

@ -5,5 +5,5 @@ test('JSONToDate is a Function', () => {
expect(JSONToDate).toBeInstanceOf(Function);
});
test('JSONToDate returns the correct date string', () => {
expect(JSONToDate(/Date(1489525200000)/)).toBe("14/3/2017");
expect(JSONToDate(/Date(1489525200000)/)).toBe('14/3/2017');
});

View File

@ -1,5 +1,5 @@
const fs = typeof require !== "undefined" && require('fs');
const crypto = typeof require !== "undefined" && require('crypto');
const fs = typeof require !== 'undefined' && require('fs');
const crypto = typeof require !== 'undefined' && require('crypto');
const CSVToArray = (data, delimiter = ',', omitFirstRow = false) =>
data
@ -963,9 +963,9 @@ const reject = (pred, array) => array.filter((...args) => !pred(...args));
const remove = (arr, func) =>
Array.isArray(arr)
? arr.filter(func).reduce((acc, val) => {
arr.splice(arr.indexOf(val), 1);
return acc.concat(val);
}, [])
arr.splice(arr.indexOf(val), 1);
return acc.concat(val);
}, [])
: [];
const removeNonASCII = str => str.replace(/[^\x20-\x7E]/g, '');
const renameKeys = (keysMap, obj) =>
@ -1337,11 +1337,11 @@ const binarySearch = (arr, val, start = 0, end = arr.length - 1) => {
const celsiusToFahrenheit = degrees => 1.8 * degrees + 32;
const cleanObj = (obj, keysToKeep = [], childIndicator) => {
Object.keys(obj).forEach(key => {
if (key === childIndicator) {
if (key === childIndicator)
cleanObj(obj[key], keysToKeep, childIndicator);
} else if (!keysToKeep.includes(key)) {
else if (!keysToKeep.includes(key))
delete obj[key];
}
});
return obj;
};
@ -1358,15 +1358,16 @@ const factors = (num, primes = false) => {
let array = Array.from({ length: num - 1 })
.map((val, i) => (num % (i + 2) === 0 ? i + 2 : false))
.filter(val => val);
if (isNeg)
if (isNeg) {
array = array.reduce((acc, val) => {
acc.push(val);
acc.push(-val);
return acc;
}, []);
}
return primes ? array.filter(isPrime) : array;
};
const fahrenheitToCelsius = degrees => (degrees - 32) * 5/9;
const fahrenheitToCelsius = degrees => (degrees - 32) * 5 / 9;
const fibonacciCountUntilNum = num =>
Math.ceil(Math.log(num * Math.sqrt(5) + 1 / 2) / Math.log((Math.sqrt(5) + 1) / 2));
const fibonacciUntilNum = num => {
@ -1377,9 +1378,9 @@ const fibonacciUntilNum = num => {
);
};
const heronArea = (side_a, side_b, side_c) => {
const p = (side_a + side_b + side_c) / 2
return Math.sqrt(p * (p-side_a) * (p-side_b) * (p-side_c))
};
const p = (side_a + side_b + side_c) / 2;
return Math.sqrt(p * (p - side_a) * (p - side_b) * (p - side_c));
};
const howManyTimes = (num, divisor) => {
if (divisor === 1 || divisor === -1) return Infinity;
if (divisor === 0) return 0;
@ -1399,8 +1400,8 @@ const httpDelete = (url, callback, err = console.error) => {
};
const httpPut = (url, data, callback, err = console.error) => {
const request = new XMLHttpRequest();
request.open("PUT", url, true);
request.setRequestHeader('Content-type','application/json; charset=utf-8');
request.open('PUT', url, true);
request.setRequestHeader('Content-type', 'application/json; charset=utf-8');
request.onload = () => callback(request);
request.onerror = () => err(request);
request.send(data);
@ -1411,13 +1412,13 @@ const isArmstrongNumber = digits =>
);
const isSimilar = (pattern, str) =>
[...str].reduce(
(matchIndex, char) =>
char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase()
? matchIndex + 1
: matchIndex,
0
(matchIndex, char) =>
char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase()
? matchIndex + 1
: matchIndex,
0
) === pattern.length;
const kmphToMph = (kmph) => 0.621371192 * kmph;
const kmphToMph = kmph => 0.621371192 * kmph;
const levenshteinDistance = (string1, string2) => {
if (string1.length === 0) return string2.length;
if (string2.length === 0) return string1.length;
@ -1429,9 +1430,9 @@ const levenshteinDistance = (string1, string2) => {
.map((x, i) => i);
for (let i = 1; i <= string2.length; i++) {
for (let j = 1; j <= string1.length; j++) {
if (string2[i - 1] === string1[j - 1]) {
if (string2[i - 1] === string1[j - 1])
matrix[i][j] = matrix[i - 1][j - 1];
} else {
else {
matrix[i][j] = Math.min(
matrix[i - 1][j - 1] + 1,
matrix[i][j - 1] + 1,
@ -1442,16 +1443,16 @@ const levenshteinDistance = (string1, string2) => {
}
return matrix[string2.length][string1.length];
};
const mphToKmph = (mph) => 1.6093440006146922 * mph;
const mphToKmph = mph => 1.6093440006146922 * mph;
const pipeLog = data => console.log(data) || data;
const quickSort = ([n, ...nums], desc) =>
isNaN(n)
? []
: [
...quickSort(nums.filter(v => (desc ? v > n : v <= n)), desc),
n,
...quickSort(nums.filter(v => (!desc ? v > n : v <= n)), desc)
];
...quickSort(nums.filter(v => (desc ? v > n : v <= n)), desc),
n,
...quickSort(nums.filter(v => (!desc ? v > n : v <= n)), desc)
];
const removeVowels = (str, repl = '') => str.replace(/[aeiou]/gi, repl);
const solveRPN = rpn => {
const OPERATORS = {
@ -1469,14 +1470,14 @@ const solveRPN = rpn => {
.filter(el => !/\s+/.test(el) && el !== '')
];
solve.forEach(symbol => {
if (!isNaN(parseFloat(symbol)) && isFinite(symbol)) {
if (!isNaN(parseFloat(symbol)) && isFinite(symbol))
stack.push(symbol);
} else if (Object.keys(OPERATORS).includes(symbol)) {
else if (Object.keys(OPERATORS).includes(symbol)) {
const [a, b] = [stack.pop(), stack.pop()];
stack.push(OPERATORS[symbol](parseFloat(b), parseFloat(a)));
} else {
} else
throw `${symbol} is not a recognized symbol`;
}
});
if (stack.length === 1) return stack.pop();
else throw `${rpn} is not a proper RPN. Please check it and try again`;
@ -1489,4 +1490,4 @@ const speechSynthesis = message => {
const squareSum = (...args) => args.reduce((squareSum, number) => squareSum + Math.pow(number, 2), 0);
module.exports = {CSVToArray,CSVToJSON,JSONToFile,JSONtoCSV,RGBToHex,URLJoin,UUIDGeneratorBrowser,UUIDGeneratorNode,all,allEqual,any,approximatelyEqual,arrayToCSV,arrayToHtmlList,ary,atob,attempt,average,averageBy,bifurcate,bifurcateBy,bind,bindAll,bindKey,binomialCoefficient,bottomVisible,btoa,byteSize,call,capitalize,capitalizeEveryWord,castArray,chainAsync,chunk,clampNumber,cloneRegExp,coalesce,coalesceFactory,collectInto,colorize,compact,compose,composeRight,converge,copyToClipboard,countBy,countOccurrences,counter,createElement,createEventHub,currentURL,curry,dayOfYear,debounce,decapitalize,deepClone,deepFlatten,deepFreeze,defaults,defer,degreesToRads,delay,detectDeviceType,difference,differenceBy,differenceWith,dig,digitize,distance,drop,dropRight,dropRightWhile,dropWhile,elementContains,elementIsVisibleInViewport,elo,equals,escapeHTML,escapeRegExp,everyNth,extendHex,factorial,fibonacci,filterNonUnique,filterNonUniqueBy,findKey,findLast,findLastIndex,findLastKey,flatten,flattenObject,flip,forEachRight,forOwn,forOwnRight,formatDuration,fromCamelCase,functionName,functions,gcd,geometricProgression,get,getColonTimeFromDate,getDaysDiffBetweenDates,getImages,getMeridiemSuffixOfInteger,getScrollPosition,getStyle,getType,getURLParameters,groupBy,hammingDistance,hasClass,hasFlags,hashBrowser,hashNode,head,hexToRGB,hide,httpGet,httpPost,httpsRedirect,hz,inRange,indentString,indexOfAll,initial,initialize2DArray,initializeArrayWithRange,initializeArrayWithRangeRight,initializeArrayWithValues,initializeNDArray,insertAfter,insertBefore,intersection,intersectionBy,intersectionWith,invertKeyValues,is,isAbsoluteURL,isAfterDate,isAnagram,isArrayLike,isBeforeDate,isBoolean,isBrowser,isBrowserTabFocused,isDivisible,isDuplexStream,isEmpty,isEven,isFunction,isLowerCase,isNil,isNull,isNumber,isObject,isObjectLike,isPlainObject,isPrime,isPrimitive,isPromiseLike,isReadableStream,isSameDate,isSorted,isStream,isString,isSymbol,isTravisCI,isUndefined,isUpperCase,isValidJSON,isWritableStream,join,last,lcm,longestItem,lowercaseKeys,luhnCheck,mapKeys,mapObject,mapString,mapValues,mask,matches,matchesWith,maxBy,maxDate,maxN,median,memoize,merge,minBy,minDate,minN,mostPerformant,negate,nest,nodeListToArray,none,nthArg,nthElement,objectFromPairs,objectToPairs,observeMutations,off,offset,omit,omitBy,on,onUserInputChange,once,orderBy,over,overArgs,pad,palindrome,parseCookie,partial,partialRight,partition,percentile,permutations,pick,pickBy,pipeAsyncFunctions,pipeFunctions,pluralize,powerset,prefix,prettyBytes,primes,promisify,pull,pullAtIndex,pullAtValue,pullBy,radsToDegrees,randomHexColorCode,randomIntArrayInRange,randomIntegerInRange,randomNumberInRange,readFileLines,rearg,recordAnimationFrames,redirect,reduceSuccessive,reduceWhich,reducedFilter,reject,remove,removeNonASCII,renameKeys,reverseString,round,runAsync,runPromisesInSeries,sample,sampleSize,scrollToTop,sdbm,serializeCookie,setStyle,shallowClone,shank,show,shuffle,similarity,size,sleep,smoothScroll,sortCharactersInString,sortedIndex,sortedIndexBy,sortedLastIndex,sortedLastIndexBy,splitLines,spreadOver,stableSort,standardDeviation,stringPermutations,stripHTMLTags,sum,sumBy,sumPower,symmetricDifference,symmetricDifferenceBy,symmetricDifferenceWith,tail,take,takeRight,takeRightWhile,takeWhile,throttle,timeTaken,times,toCamelCase,toCurrency,toDecimalMark,toHash,toKebabCase,toOrdinalSuffix,toSafeInteger,toSnakeCase,toTitleCase,toggleClass,tomorrow,transform,triggerEvent,truncateString,truthCheckCollection,unary,uncurry,unescapeHTML,unflattenObject,unfold,union,unionBy,unionWith,uniqueElements,uniqueElementsBy,uniqueElementsByRight,uniqueSymmetricDifference,untildify,unzip,unzipWith,validateNumber,when,without,words,xProd,yesNo,zip,zipObject,zipWith,JSONToDate,binarySearch,celsiusToFahrenheit,cleanObj,collatz,countVowels,factors,fahrenheitToCelsius,fibonacciCountUntilNum,fibonacciUntilNum,heronArea,howManyTimes,httpDelete,httpPut,isArmstrongNumber,isSimilar,kmphToMph,levenshteinDistance,mphToKmph,pipeLog,quickSort,removeVowels,solveRPN,speechSynthesis,squareSum}
module.exports = {CSVToArray, CSVToJSON, JSONToFile, JSONtoCSV, RGBToHex, URLJoin, UUIDGeneratorBrowser, UUIDGeneratorNode, all, allEqual, any, approximatelyEqual, arrayToCSV, arrayToHtmlList, ary, atob, attempt, average, averageBy, bifurcate, bifurcateBy, bind, bindAll, bindKey, binomialCoefficient, bottomVisible, btoa, byteSize, call, capitalize, capitalizeEveryWord, castArray, chainAsync, chunk, clampNumber, cloneRegExp, coalesce, coalesceFactory, collectInto, colorize, compact, compose, composeRight, converge, copyToClipboard, countBy, countOccurrences, counter, createElement, createEventHub, currentURL, curry, dayOfYear, debounce, decapitalize, deepClone, deepFlatten, deepFreeze, defaults, defer, degreesToRads, delay, detectDeviceType, difference, differenceBy, differenceWith, dig, digitize, distance, drop, dropRight, dropRightWhile, dropWhile, elementContains, elementIsVisibleInViewport, elo, equals, escapeHTML, escapeRegExp, everyNth, extendHex, factorial, fibonacci, filterNonUnique, filterNonUniqueBy, findKey, findLast, findLastIndex, findLastKey, flatten, flattenObject, flip, forEachRight, forOwn, forOwnRight, formatDuration, fromCamelCase, functionName, functions, gcd, geometricProgression, get, getColonTimeFromDate, getDaysDiffBetweenDates, getImages, getMeridiemSuffixOfInteger, getScrollPosition, getStyle, getType, getURLParameters, groupBy, hammingDistance, hasClass, hasFlags, hashBrowser, hashNode, head, hexToRGB, hide, httpGet, httpPost, httpsRedirect, hz, inRange, indentString, indexOfAll, initial, initialize2DArray, initializeArrayWithRange, initializeArrayWithRangeRight, initializeArrayWithValues, initializeNDArray, insertAfter, insertBefore, intersection, intersectionBy, intersectionWith, invertKeyValues, is, isAbsoluteURL, isAfterDate, isAnagram, isArrayLike, isBeforeDate, isBoolean, isBrowser, isBrowserTabFocused, isDivisible, isDuplexStream, isEmpty, isEven, isFunction, isLowerCase, isNil, isNull, isNumber, isObject, isObjectLike, isPlainObject, isPrime, isPrimitive, isPromiseLike, isReadableStream, isSameDate, isSorted, isStream, isString, isSymbol, isTravisCI, isUndefined, isUpperCase, isValidJSON, isWritableStream, join, last, lcm, longestItem, lowercaseKeys, luhnCheck, mapKeys, mapObject, mapString, mapValues, mask, matches, matchesWith, maxBy, maxDate, maxN, median, memoize, merge, minBy, minDate, minN, mostPerformant, negate, nest, nodeListToArray, none, nthArg, nthElement, objectFromPairs, objectToPairs, observeMutations, off, offset, omit, omitBy, on, onUserInputChange, once, orderBy, over, overArgs, pad, palindrome, parseCookie, partial, partialRight, partition, percentile, permutations, pick, pickBy, pipeAsyncFunctions, pipeFunctions, pluralize, powerset, prefix, prettyBytes, primes, promisify, pull, pullAtIndex, pullAtValue, pullBy, radsToDegrees, randomHexColorCode, randomIntArrayInRange, randomIntegerInRange, randomNumberInRange, readFileLines, rearg, recordAnimationFrames, redirect, reduceSuccessive, reduceWhich, reducedFilter, reject, remove, removeNonASCII, renameKeys, reverseString, round, runAsync, runPromisesInSeries, sample, sampleSize, scrollToTop, sdbm, serializeCookie, setStyle, shallowClone, shank, show, shuffle, similarity, size, sleep, smoothScroll, sortCharactersInString, sortedIndex, sortedIndexBy, sortedLastIndex, sortedLastIndexBy, splitLines, spreadOver, stableSort, standardDeviation, stringPermutations, stripHTMLTags, sum, sumBy, sumPower, symmetricDifference, symmetricDifferenceBy, symmetricDifferenceWith, tail, take, takeRight, takeRightWhile, takeWhile, throttle, timeTaken, times, toCamelCase, toCurrency, toDecimalMark, toHash, toKebabCase, toOrdinalSuffix, toSafeInteger, toSnakeCase, toTitleCase, toggleClass, tomorrow, transform, triggerEvent, truncateString, truthCheckCollection, unary, uncurry, unescapeHTML, unflattenObject, unfold, union, unionBy, unionWith, uniqueElements, uniqueElementsBy, uniqueElementsByRight, uniqueSymmetricDifference, untildify, unzip, unzipWith, validateNumber, when, without, words, xProd, yesNo, zip, zipObject, zipWith, JSONToDate, binarySearch, celsiusToFahrenheit, cleanObj, collatz, countVowels, factors, fahrenheitToCelsius, fibonacciCountUntilNum, fibonacciUntilNum, heronArea, howManyTimes, httpDelete, httpPut, isArmstrongNumber, isSimilar, kmphToMph, levenshteinDistance, mphToKmph, pipeLog, quickSort, removeVowels, solveRPN, speechSynthesis, squareSum};

View File

@ -6,7 +6,7 @@ test('bindAll is a Function', () => {
});
var view = {
label: 'docs',
click: function() {
click() {
return 'clicked ' + this.label;
}
};

View File

@ -6,7 +6,7 @@ test('bindKey is a Function', () => {
});
const freddy = {
user: 'fred',
greet: function(greeting, punctuation) {
greet(greeting, punctuation) {
return greeting + ' ' + this.user + punctuation;
}
};

View File

@ -6,21 +6,21 @@ test('celsiusToFahrenheit is a Function', () => {
});
test('0 Celsius is 32 Fahrenheit', () => {
expect(celsiusToFahrenheit(0)).toBe(32)
})
expect(celsiusToFahrenheit(0)).toBe(32);
});
test('100 Celsius is 212 Fahrenheit', () => {
expect(celsiusToFahrenheit(100)).toBe(212)
})
expect(celsiusToFahrenheit(100)).toBe(212);
});
test('-50 Celsius is -58 Fahrenheit', () => {
expect(celsiusToFahrenheit(-50)).toBe(-58)
})
expect(celsiusToFahrenheit(-50)).toBe(-58);
});
test('1000 Celsius is 1832 Fahrenheit', () => {
expect(celsiusToFahrenheit(1000)).toBe(1832)
})
expect(celsiusToFahrenheit(1000)).toBe(1832);
});
test('Not a number value is NaN', () => {
expect(celsiusToFahrenheit("Durr")).toBe(NaN)
})
expect(celsiusToFahrenheit('Durr')).toBe(NaN);
});

View File

@ -5,27 +5,27 @@ test('copyToClipboard is a Function', () => {
expect(copyToClipboard).toBeInstanceOf(Function);
});
test('copyToClipboard does not throw errors', () => {
document.getSelection = function () {
document.getSelection = function() {
return {
rangeCount: 0,
removeAllRanges() { return; },
addRange(x) { return x; }
};
}
document.execCommand = function (x) { return x; }
};
document.execCommand = function(x) { return x; };
expect(copyToClipboard('hi')).toBe(undefined);
});
test('copyToClipboard does not throw errors', () => {
document.getSelection = function () {
document.getSelection = function() {
return {
rangeCount: 1,
getRangeAt(x) { return x+1; },
getRangeAt(x) { return x + 1; },
removeAllRanges() { return; },
addRange(x) { return x; }
};
}
document.execCommand = function (x) { return x; }
};
document.execCommand = function(x) { return x; };
expect(copyToClipboard('hi')).toBe(undefined);
});

View File

@ -6,21 +6,21 @@ test('fahrenheitToCelsius is a Function', () => {
});
test('32 Fahrenheit is 0 Celsius', () => {
expect(fahrenheitToCelsius(32)).toBe(0)
})
expect(fahrenheitToCelsius(32)).toBe(0);
});
test('212 Fahrenheit is 100 Celsius', () => {
expect(fahrenheitToCelsius(212)).toBe(100)
})
expect(fahrenheitToCelsius(212)).toBe(100);
});
test('150 Fahrenheit is 65.55555555555556 Celsius', () => {
expect(fahrenheitToCelsius(150)).toBe(65.55555555555556)
})
expect(fahrenheitToCelsius(150)).toBe(65.55555555555556);
});
test('1000 Fahrenheit is 537.7777777777778', () => {
expect(fahrenheitToCelsius(1000)).toBe(537.7777777777778)
})
expect(fahrenheitToCelsius(1000)).toBe(537.7777777777778);
});
test('Not a number value is NaN', () => {
expect(fahrenheitToCelsius("Durr")).toBe(NaN)
})
expect(fahrenheitToCelsius('Durr')).toBe(NaN);
});

View File

@ -7,4 +7,4 @@ test('getColonTimeFromDate is a Function', () => {
test('Gets the time in the proper format.', () => {
let date = new Date();
expect(getColonTimeFromDate(date)).toEqual(date.toTimeString().slice(0, 8));
});
});

View File

@ -1,18 +1,18 @@
const expect = require("expect");
const {getImages} = require("./_30s.js");
const jsdom = require("jsdom");
const expect = require('expect');
const {getImages} = require('./_30s.js');
const jsdom = require('jsdom');
const { JSDOM } = jsdom;
const TEST_HTML = new JSDOM("<!DOCTYPE html><p>Hello world</p><img src=\"https://upload.wikimedia.org/wikipedia/en/1/12/Yellow_Smiley_Face.png\"></img>").window.document;
const TEST_HTML = new JSDOM('<!DOCTYPE html><p>Hello world</p><img src="https://upload.wikimedia.org/wikipedia/en/1/12/Yellow_Smiley_Face.png"></img>').window.document;
test("getImages is a Function", () => {
expect(getImages).toBeInstanceOf(Function);
test('getImages is a Function', () => {
expect(getImages).toBeInstanceOf(Function);
});
test("getImages returns an Array", () => {
expect(getImages(TEST_HTML)).toBeInstanceOf(Array);
test('getImages returns an Array', () => {
expect(getImages(TEST_HTML)).toBeInstanceOf(Array);
});
test("getImages removes duplicates from images Array", () => {
expect(getImages(TEST_HTML, false).length).toBeLessThanOrEqual(getImages(TEST_HTML, true).length);
expect(getImages(TEST_HTML, true)).toEqual(expect.arrayContaining(getImages(TEST_HTML, false)));
test('getImages removes duplicates from images Array', () => {
expect(getImages(TEST_HTML, false).length).toBeLessThanOrEqual(getImages(TEST_HTML, true).length);
expect(getImages(TEST_HTML, true)).toEqual(expect.arrayContaining(getImages(TEST_HTML, false)));
});

View File

@ -9,4 +9,4 @@ test('httpGet does not throw errors', () => {
httpGet('http://localhost', x => x, console.log);
httpGet('http://localhost', x => x);
}).not.toThrow(TypeError);
});
});

View File

@ -8,5 +8,5 @@ test('Initializes a n-D array with given data', () => {
expect(initializeNDArray(1, 3)).toEqual([1, 1, 1]);
});
test('Initializes a n-D array with given data', () => {
expect(initializeNDArray(5, 2, 2, 2)).toEqual([[[5, 5], [5, 5]],[[5, 5], [5, 5]]]);
expect(initializeNDArray(5, 2, 2, 2)).toEqual([[[5, 5], [5, 5]], [[5, 5], [5, 5]]]);
});

View File

@ -5,7 +5,7 @@ test('insertAfter is a Function', () => {
expect(insertAfter).toBeInstanceOf(Function);
});
let e = document.createElement('div');
e.setAttribute("id", "test");
e.setAttribute('id', 'test');
test('Does not throw error if the element exists', () => {
expect(() => {
insertAfter(e, '<span>test</span>');

View File

@ -5,7 +5,7 @@ test('insertBefore is a Function', () => {
expect(insertBefore).toBeInstanceOf(Function);
});
let e = document.createElement('div');
e.setAttribute("id", "test");
e.setAttribute('id', 'test');
test('Does not throw error if the element exists', () => {
expect(() => {
insertBefore(e, '<span>test</span>');

View File

@ -7,7 +7,7 @@ test('isPromiseLike is a Function', () => {
test('Returns true for a promise-like object', () => {
expect(
isPromiseLike({
then: function() {
then() {
return '';
}
})

View File

@ -4,11 +4,12 @@ const {isTravisCI} = require('./_30s.js');
test('isTravisCI is a Function', () => {
expect(isTravisCI).toBeInstanceOf(Function);
});
if (isTravisCI())
if (isTravisCI()) {
test('Running on Travis, correctly evaluates', () => {
expect(isTravisCI()).toBeTruthy();
});
else
} else {
test('Not running on Travis, correctly evaluates', () => {
expect(isTravisCI()).toBeFalsy();
});
}

View File

@ -1,21 +1,21 @@
const expect = require("expect");
const {shank} = require("./_30s.js");
const expect = require('expect');
const {shank} = require('./_30s.js');
test("shank is a Function", () => {
test('shank is a Function', () => {
expect(shank).toBeInstanceOf(Function);
});
const names = ['alpha', 'bravo', 'charlie'];
test("Returns an array with the added elements.", () => {
test('Returns an array with the added elements.', () => {
expect(shank(names, 1, 0, 'delta')).toEqual(['alpha', 'delta', 'bravo', 'charlie']);
});
test("Returns an array with the removed elements.", () => {
test('Returns an array with the removed elements.', () => {
expect(shank(names, 1, 1)).toEqual(['alpha', 'charlie']);
});
test("Does not mutate the original array", () => {
test('Does not mutate the original array', () => {
shank(names, 1, 0, 'delta');
expect(names).toEqual(['alpha', 'bravo', 'charlie']);
});

View File

@ -9,4 +9,4 @@ test('Works with a callback.', () => {
});
test('Works with a property name.', () => {
expect(sumBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n')).toBe(20);
});
});

View File

@ -9,6 +9,6 @@ test('triggerEvent triggers an event', () => {
let val = false;
const fn = () => val = true;
el.addEventListener('click', fn);
triggerEvent(el, 'click', {})
triggerEvent(el, 'click', {});
expect(val).toBeTruthy();
});