Test cleanup and fixes [e-f]
This commit is contained in:
@ -1,10 +1,6 @@
|
||||
const expect = require('expect');
|
||||
const elementIsVisibleInViewport = require('./elementIsVisibleInViewport.js');
|
||||
|
||||
|
||||
test('elementIsVisibleInViewport is a Function', () => {
|
||||
expect(elementIsVisibleInViewport).toBeInstanceOf(Function);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
const expect = require('expect');
|
||||
const elo = require('./elo.js');
|
||||
|
||||
|
||||
test('elo is a Function', () => {
|
||||
expect(elo).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Standard 1v1s', () => {
|
||||
expect(elo([1200, 1200]), [1216).toEqual(1184])
|
||||
expect(elo([1200, 1200])).toEqual([1216,1184]);
|
||||
});
|
||||
test('Standard 1v1s' ,() => {
|
||||
expect(elo([1200, 1200], 64)).toBe([1232, 1168]);
|
||||
});
|
||||
t.deepEqual(elo([1200, 1200], 64), [1232, 1168]), "Standard 1v1s";
|
||||
test('4 player FFA, all same rank', () => {
|
||||
expect(elo([1200, 1200, 1200, 1200]).map(Math.round), [1246, 1215, 1185).toEqual(1154])
|
||||
expect(elo([1200, 1200, 1200, 1200]).map(Math.round)).toEqual([1246, 1215, 1185, 1154]);
|
||||
});
|
||||
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
const expect = require('expect');
|
||||
const equals = require('./equals.js');
|
||||
|
||||
|
||||
test('equals is a Function', () => {
|
||||
expect(equals).toBeInstanceOf(Function);
|
||||
});
|
||||
test('{ a: [2, {e: 3}], b: [4], c: 'foo' } is equal to { a: [2, {e: 3}], b: [4], c: 'foo' }', () => {
|
||||
expect(equals({ a: [2, {e: 3}], b: [4], c: 'foo' }, { a: [2, {e: 3}], b: [4], c: 'foo' })).toBeTruthy()
|
||||
expect(equals({ a: [2, {e: 3}], b: [4], c: 'foo' }, { a: [2, {e: 3}], b: [4], c: 'foo' })).toBeTruthy();
|
||||
});
|
||||
test('[1,2,3] is equal to [1,2,3]', () => {
|
||||
expect(equals([1, 2, 3], [1, 2, 3])).toBeTruthy();
|
||||
@ -20,5 +19,3 @@ const equals = require('./equals.js');
|
||||
test('[1, 2, 3] should be equal to { 0: 1, 1: 2, 2: 3 }) - type is different, but their enumerable properties match.', () => {
|
||||
expect(equals([1, 2, 3], { 0: 1, 1: 2, 2: 3 })).toBeTruthy();
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const escapeHTML = require('./escapeHTML.js');
|
||||
|
||||
|
||||
test('escapeHTML is a Function', () => {
|
||||
expect(escapeHTML).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Escapes a string for use in HTML', () => {
|
||||
expect(escapeHTML('<a href="#">Me & you</a>')).toBe('<a href="#">Me & you</a>')
|
||||
});
|
||||
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const escapeRegExp = require('./escapeRegExp.js');
|
||||
|
||||
|
||||
test('escapeRegExp is a Function', () => {
|
||||
expect(escapeRegExp).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Escapes a string to use in a regular expression', () => {
|
||||
expect(escapeRegExp('(test)')).toBe('\\(test\\)')
|
||||
});
|
||||
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const everyNth = require('./everyNth.js');
|
||||
|
||||
|
||||
test('everyNth is a Function', () => {
|
||||
expect(everyNth).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Returns every nth element in an array', () => {
|
||||
expect(everyNth([1, 2, 3, 4, 5, 6], 2), [ 2, 4).toEqual(6 ])
|
||||
expect(everyNth([1, 2, 3, 4, 5, 6], 2)).toEqual([ 2, 4, 6 ]);
|
||||
});
|
||||
|
||||
|
||||
@ -1,14 +1,12 @@
|
||||
const expect = require('expect');
|
||||
const extendHex = require('./extendHex.js');
|
||||
|
||||
|
||||
test('extendHex is a Function', () => {
|
||||
expect(extendHex).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Extends a 3-digit color code to a 6-digit color code', () => {
|
||||
expect(extendHex('#03f')).toBe('#0033ff')
|
||||
expect(extendHex('#03f')).toBe('#0033ff');
|
||||
});
|
||||
test('Extends a 3-digit color code to a 6-digit color code', () => {
|
||||
expect(extendHex('05a')).toBe('#0055aa')
|
||||
expect(extendHex('05a')).toBe('#0055aa');
|
||||
});
|
||||
|
||||
|
||||
@ -1,23 +1,21 @@
|
||||
const expect = require('expect');
|
||||
const factorial = require('./factorial.js');
|
||||
|
||||
|
||||
test('factorial is a Function', () => {
|
||||
expect(factorial).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Calculates the factorial of 720', () => {
|
||||
expect(factorial(6)).toBe(720)
|
||||
expect(factorial(6)).toBe(720);
|
||||
});
|
||||
test('Calculates the factorial of 0', () => {
|
||||
expect(factorial(0)).toBe(1)
|
||||
expect(factorial(0)).toBe(1);
|
||||
});
|
||||
test('Calculates the factorial of 1', () => {
|
||||
expect(factorial(1)).toBe(1)
|
||||
expect(factorial(1)).toBe(1);
|
||||
});
|
||||
test('Calculates the factorial of 4', () => {
|
||||
expect(factorial(4)).toBe(24)
|
||||
expect(factorial(4)).toBe(24);
|
||||
});
|
||||
test('Calculates the factorial of 10', () => {
|
||||
expect(factorial(10)).toBe(3628800)
|
||||
expect(factorial(10)).toBe(3628800);
|
||||
});
|
||||
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
const expect = require('expect');
|
||||
const factors = require('./factors.js');
|
||||
|
||||
|
||||
test('factors is a Function', () => {
|
||||
expect(factors).toBeInstanceOf(Function);
|
||||
});
|
||||
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const fibonacci = require('./fibonacci.js');
|
||||
|
||||
|
||||
test('fibonacci is a Function', () => {
|
||||
expect(fibonacci).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Generates an array, containing the Fibonacci sequence', () => {
|
||||
expect(fibonacci(6), [0, 1, 1, 2, 3).toEqual(5])
|
||||
expect(fibonacci(6)).toEqual([0, 1, 1, 2, 3, 5]);
|
||||
});
|
||||
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
const expect = require('expect');
|
||||
const fibonacciCountUntilNum = require('./fibonacciCountUntilNum.js');
|
||||
|
||||
|
||||
test('fibonacciCountUntilNum is a Function', () => {
|
||||
expect(fibonacciCountUntilNum).toBeInstanceOf(Function);
|
||||
});
|
||||
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
const expect = require('expect');
|
||||
const fibonacciUntilNum = require('./fibonacciUntilNum.js');
|
||||
|
||||
|
||||
test('fibonacciUntilNum is a Function', () => {
|
||||
expect(fibonacciUntilNum).toBeInstanceOf(Function);
|
||||
});
|
||||
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
const expect = require('expect');
|
||||
const filterNonUnique = require('./filterNonUnique.js');
|
||||
|
||||
|
||||
test('filterNonUnique is a Function', () => {
|
||||
expect(filterNonUnique).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Filters out the non-unique values in an array', () => {
|
||||
expect(filterNonUnique([1, 2, 2, 3, 4, 4, 5]), [1,3).toEqual(5])
|
||||
expect(filterNonUnique([1, 2, 2, 3, 4, 4, 5])).toEqual([1,3, 5]);
|
||||
});
|
||||
|
||||
|
||||
@ -1,17 +1,15 @@
|
||||
const expect = require('expect');
|
||||
const findKey = require('./findKey.js');
|
||||
|
||||
|
||||
test('findKey is a Function', () => {
|
||||
expect(findKey).toBeInstanceOf(Function);
|
||||
});
|
||||
t.deepEqual(findKey(
|
||||
test('Returns the appropriate key', () => {
|
||||
expect(findKey(
|
||||
{
|
||||
barney: { age: 36, active: true },
|
||||
fred: { age: 40, active: false },
|
||||
pebbles: { age: 1, active: true }
|
||||
},
|
||||
o => o['active']
|
||||
), 'barney', 'Returns the appropriate key');
|
||||
|
||||
|
||||
o => o['active']).toBe('barney');
|
||||
});
|
||||
|
||||
@ -1,12 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const findLast = require('./findLast.js');
|
||||
|
||||
|
||||
test('findLast is a Function', () => {
|
||||
expect(findLast).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Finds last element for which the given function returns true', () => {
|
||||
expect(findLast([1, 2, 3, 4], n => n % 2 === 1), 3).toBe()
|
||||
expect(findLast([1, 2, 3, 4], n => n % 2 === 1)).toBe(3);
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -1,12 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const findLastIndex = require('./findLastIndex.js');
|
||||
|
||||
|
||||
test('findLastIndex is a Function', () => {
|
||||
expect(findLastIndex).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Finds last index for which the given function returns true', () => {
|
||||
expect(findLastIndex([1, 2, 3, 4], n => n % 2 === 1), 2).toBe()
|
||||
expect(findLastIndex([1, 2, 3, 4], n => n % 2 === 1)).toBe(2);
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -1,17 +1,15 @@
|
||||
const expect = require('expect');
|
||||
const findLastKey = require('./findLastKey.js');
|
||||
|
||||
|
||||
test('findLastKey is a Function', () => {
|
||||
expect(findLastKey).toBeInstanceOf(Function);
|
||||
});
|
||||
t.equal(findLastKey(
|
||||
test('eturns the appropriate key', () => {
|
||||
expect(findLastKey(
|
||||
{
|
||||
barney: { age: 36, active: true },
|
||||
fred: { age: 40, active: false },
|
||||
pebbles: { age: 1, active: true }
|
||||
},
|
||||
o => o['active']
|
||||
), 'pebbles', 'Returns the appropriate key');
|
||||
|
||||
|
||||
o => o['active']).toBe('pebbles');
|
||||
});
|
||||
|
||||
@ -1,14 +1,12 @@
|
||||
const expect = require('expect');
|
||||
const flatten = require('./flatten.js');
|
||||
|
||||
|
||||
test('flatten is a Function', () => {
|
||||
expect(flatten).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Flattens an array', () => {
|
||||
expect(flatten([1, [2], 3, 4]), [1, 2, 3).toEqual(4])
|
||||
expect(flatten([1, [2], 3, 4])).toEqual([1, 2, 3, 4]);
|
||||
});
|
||||
test('Flattens an array', () => {
|
||||
expect(flatten([1, [2, [3, [4, 5], 6], 7], 8], 2), [1, 2, 3, [4, 5], 6, 7).toEqual(8])
|
||||
expect(flatten([1, [2, [3, [4, 5], 6], 7], 8], 2)).toEqual([1, 2, 3, [4, 5], 6, 7, 8]);
|
||||
});
|
||||
|
||||
|
||||
@ -1,15 +1,12 @@
|
||||
const expect = require('expect');
|
||||
const flattenObject = require('./flattenObject.js');
|
||||
|
||||
|
||||
test('flattenObject is a Function', () => {
|
||||
expect(flattenObject).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Flattens an object with the paths for keys', () => {
|
||||
expect(flattenObject({ a: { b: { c: 1 } }, d: 1 }), { 'a.b.c': 1, d: 1 }).toEqual()
|
||||
expect(flattenObject({ a: { b: { c: 1 } }, d: 1 })).toEqual({ 'a.b.c': 1, d: 1 });
|
||||
});
|
||||
test('Works with arrays', () => {
|
||||
expect(flattenObject([0,1,[2,[1]],1]), { 0: 0, 1: 1, 3: 1, '2.0': 2, '2.1.0': 1 }).toEqual()
|
||||
expect(flattenObject([0,1,[2,[1]],1])).toEqual({ 0: 0, 1: 1, 3: 1, '2.0': 2, '2.1.0': 1 });
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
const expect = require('expect');
|
||||
const flip = require('./flip.js');
|
||||
|
||||
|
||||
test('flip is a Function', () => {
|
||||
expect(flip).toBeInstanceOf(Function);
|
||||
});
|
||||
@ -10,7 +9,5 @@ const flip = require('./flip.js');
|
||||
const mergeFrom = flip(Object.assign);
|
||||
let mergePerson = mergeFrom.bind(null, a);
|
||||
test('Flips argument order', () => {
|
||||
expect(mergePerson(b), a).toEqual()
|
||||
expect(mergePerson(b)).toEqual(a);
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -1,14 +1,11 @@
|
||||
const expect = require('expect');
|
||||
const forEachRight = require('./forEachRight.js');
|
||||
|
||||
|
||||
test('forEachRight is a Function', () => {
|
||||
expect(forEachRight).toBeInstanceOf(Function);
|
||||
});
|
||||
let output = '';
|
||||
forEachRight([1, 2, 3, 4], val => output+=val);
|
||||
test('Iterates over the array in reverse', () => {
|
||||
expect(output, '4321').toBe()
|
||||
expect(output).toBe('4321')
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -1,14 +1,11 @@
|
||||
const expect = require('expect');
|
||||
const forOwn = require('./forOwn.js');
|
||||
|
||||
|
||||
test('forOwn is a Function', () => {
|
||||
expect(forOwn).toBeInstanceOf(Function);
|
||||
});
|
||||
let output = [];
|
||||
forOwn({ foo: 'bar', a: 1 }, v => output.push(v));
|
||||
test('Iterates over an element\'s key-value pairs', () => {
|
||||
expect(output, ['bar', 1]).toEqual()
|
||||
expect(output).toEqual(['bar', 1]);
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -1,14 +1,11 @@
|
||||
const expect = require('expect');
|
||||
const forOwnRight = require('./forOwnRight.js');
|
||||
|
||||
|
||||
test('forOwnRight is a Function', () => {
|
||||
expect(forOwnRight).toBeInstanceOf(Function);
|
||||
});
|
||||
let output = [];
|
||||
forOwnRight({ foo: 'bar', a: 1 }, v => output.push(v));
|
||||
test('Iterates over an element\'s key-value pairs in reverse', () => {
|
||||
expect(output, [1, 'bar']).toEqual()
|
||||
expect(output).toEqual([1, 'bar']);
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -1,14 +1,12 @@
|
||||
const expect = require('expect');
|
||||
const formatDuration = require('./formatDuration.js');
|
||||
|
||||
|
||||
test('formatDuration is a Function', () => {
|
||||
expect(formatDuration).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Returns the human readable format of the given number of milliseconds', () => {
|
||||
expect(formatDuration(1001), '1 second).toBe(1 millisecond')
|
||||
expect(formatDuration(1001)).toBe('1 second, 1 millisecond');
|
||||
});
|
||||
test('Returns the human readable format of the given number of milliseconds', () => {
|
||||
expect(formatDuration(34325055574), '397 days, 6 hours, 44 minutes, 15 seconds).toBe(574 milliseconds')
|
||||
expect(formatDuration(34325055574)).toBe('397 days, 6 hours, 44 minutes, 15 seconds, 574 milliseconds');
|
||||
});
|
||||
|
||||
|
||||
@ -1,17 +1,15 @@
|
||||
const expect = require('expect');
|
||||
const fromCamelCase = require('./fromCamelCase.js');
|
||||
|
||||
|
||||
test('fromCamelCase is a Function', () => {
|
||||
expect(fromCamelCase).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Converts a string from camelcase', () => {
|
||||
expect(fromCamelCase('someDatabaseFieldName', ' ')).toBe('some database field name')
|
||||
expect(fromCamelCase('someDatabaseFieldName', ' ')).toBe('some database field name');
|
||||
});
|
||||
test('Converts a string from camelcase', () => {
|
||||
expect(fromCamelCase('someLabelThatNeedsToBeCamelized', '-')).toBe('some-label-that-needs-to-be-camelized')
|
||||
expect(fromCamelCase('someLabelThatNeedsToBeCamelized', '-')).toBe('some-label-that-needs-to-be-camelized');
|
||||
});
|
||||
test('Converts a string from camelcase', () => {
|
||||
expect(fromCamelCase('someJavascriptProperty', '_')).toBe('some_javascript_property')
|
||||
expect(fromCamelCase('someJavascriptProperty', '_')).toBe('some_javascript_property');
|
||||
});
|
||||
|
||||
|
||||
@ -9,17 +9,15 @@ const functionName = fn => (console.debug(fn.name), fn);
|
||||
});
|
||||
functionName(Math.max);
|
||||
test('Works for native functions', () => {
|
||||
expect(output, 'max').toBe()
|
||||
expect(output).toBe('max');
|
||||
});
|
||||
function fun(x) {return x;}
|
||||
functionName(fun);
|
||||
test('Works for functions', () => {
|
||||
expect(output, 'fun').toBe()
|
||||
expect(output).toBe('fun');
|
||||
});
|
||||
const fn = x => x;
|
||||
functionName(fn);
|
||||
test('Works for arrow functions', () => {
|
||||
expect(output, 'fn').toBe()
|
||||
expect(output).toBe('fn');
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
const expect = require('expect');
|
||||
const functions = require('./functions.js');
|
||||
|
||||
|
||||
test('functions is a Function', () => {
|
||||
expect(functions).toBeInstanceOf(Function);
|
||||
});
|
||||
@ -11,10 +10,8 @@ const functions = require('./functions.js');
|
||||
}
|
||||
Foo.prototype.c = () => 3;
|
||||
test('Returns own methods', () => {
|
||||
expect(functions(new Foo()), ['a', 'b']).toEqual()
|
||||
expect(functions(new Foo()).toEqual( ['a', 'b']);
|
||||
});
|
||||
test('Returns own and inherited methods', () => {
|
||||
expect(functions(new Foo(), true), ['a', 'b', 'c']).toEqual()
|
||||
expect(functions(new Foo(), true)).toEqual(['a', 'b', 'c']);
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user