diff --git a/snippets/toHash.md b/snippets/toHash.md index 002fe8e92..6ebc38907 100644 --- a/snippets/toHash.md +++ b/snippets/toHash.md @@ -14,7 +14,7 @@ const toHash = (object, key) => ``` ```js -toHash([4, 3, 2, 1]); // { 0: 4, 1: 3, 2: 2, 1: 1 } +toHash([4, 3, 2, 1]); // { 0: 4, 1: 3, 2: 2, 3: 1 } toHash([{ a: 'label' }], 'a'); // { label: { a: 'label' } } // A more in depth example: let users = [{ id: 1, first: 'Jon' }, { id: 2, first: 'Joe' }, { id: 3, first: 'Moe' }]; diff --git a/test/bottomVisible.test.js b/test/bottomVisible.test.js index 591d985b0..ea9170790 100644 --- a/test/bottomVisible.test.js +++ b/test/bottomVisible.test.js @@ -4,3 +4,6 @@ const {bottomVisible} = require('./_30s.js'); test('bottomVisible is a Function', () => { expect(bottomVisible).toBeInstanceOf(Function); }); +test('bottomVisible returns a boolean', () => { + expect(typeof bottomVisible()).toBe('boolean'); +}); diff --git a/test/sortedIndex.test.js b/test/sortedIndex.test.js index bf1606098..9b4d1a83f 100644 --- a/test/sortedIndex.test.js +++ b/test/sortedIndex.test.js @@ -10,3 +10,6 @@ test('Returns the lowest index at which value should be inserted into array in o 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); }); +test('Returns the lowest index at which value should be inserted into array in order to maintain its sort order.', () => { + expect(sortedIndex([30, 50], 60)).toBe(2); +}); diff --git a/test/sortedIndexBy.test.js b/test/sortedIndexBy.test.js index 65545dd7f..5ac4186ce 100644 --- a/test/sortedIndexBy.test.js +++ b/test/sortedIndexBy.test.js @@ -7,3 +7,9 @@ test('sortedIndexBy is a Function', () => { 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)).toBe(0); }); +test('Returns the lowest index to insert the element without messing up the list order', () => { + expect(sortedIndexBy([{ x: 5 }, { x: 4 }], { x: 4 }, o => o.x)).toBe(1); +}); +test('Returns the lowest index to insert the element without messing up the list order', () => { + expect(sortedIndexBy([{ x: 4 }, { x: 5 }], { x: 6 }, o => o.x)).toBe(2); +}); diff --git a/test/sortedLastIndex.test.js b/test/sortedLastIndex.test.js index 789fcc188..718a74c52 100644 --- a/test/sortedLastIndex.test.js +++ b/test/sortedLastIndex.test.js @@ -7,3 +7,9 @@ test('sortedLastIndex is a Function', () => { test('Returns the highest index to insert the element without messing up the list order', () => { expect(sortedLastIndex([10, 20, 30, 30, 40], 30)).toBe(4); }); +test('Returns the highest index to insert the element without messing up the list order', () => { + expect(sortedLastIndex([40, 30, 10], 20)).toBe(2); +}); +test('Returns the highest index to insert the element without messing up the list order', () => { + expect(sortedLastIndex([10, 20, 30, 30, 40], 5)).toBe(0); +}); diff --git a/test/sortedLastIndexBy.test.js b/test/sortedLastIndexBy.test.js index 8185bed93..6d3c203f3 100644 --- a/test/sortedLastIndexBy.test.js +++ b/test/sortedLastIndexBy.test.js @@ -7,3 +7,9 @@ test('sortedLastIndexBy is a Function', () => { 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)).toBe(1); }); +test('Returns the highest index to insert the element without messing up the list order', () => { + expect(sortedLastIndexBy([{ x: 5 }, { x: 4 }], { x: 5 }, o => o.x)).toBe(1); +}); +test('Returns the highest index to insert the element without messing up the list order', () => { + expect(sortedLastIndexBy([{ x: 4 }, { x: 5 }], { x: 3 }, o => o.x)).toBe(0); +}); diff --git a/test/squareSum.test.js b/test/squareSum.test.js index 08b60a65c..13b31a2af 100644 --- a/test/squareSum.test.js +++ b/test/squareSum.test.js @@ -4,3 +4,6 @@ const {squareSum} = require('./_30s.js'); test('squareSum is a Function', () => { expect(squareSum).toBeInstanceOf(Function); }); +test('squareSum returns the proper result', () => { + expect(squareSum(2, 3, 4)).toBe(29); +}); diff --git a/test/throttle.test.js b/test/throttle.test.js index 646e93fa3..f1b4578d3 100644 --- a/test/throttle.test.js +++ b/test/throttle.test.js @@ -4,3 +4,8 @@ const {throttle} = require('./_30s.js'); test('throttle is a Function', () => { expect(throttle).toBeInstanceOf(Function); }); +test('throttle returns a function', () => { + let throttled = throttle(x => x, 100000); + expect(throttled).toBeInstanceOf(Function); + expect(throttled(10)).toBe(undefined); +}); diff --git a/test/toHash.test.js b/test/toHash.test.js index 7913d0591..8e742a86b 100644 --- a/test/toHash.test.js +++ b/test/toHash.test.js @@ -4,3 +4,9 @@ const {toHash} = require('./_30s.js'); test('toHash is a Function', () => { expect(toHash).toBeInstanceOf(Function); }); +test('toHash works properly with indexes', () => { + expect(toHash([4, 3, 2, 1])).toEqual({ 0: 4, 1: 3, 2: 2, 3: 1 }); +}); +test('toHash works properly with keys', () => { + expect(toHash([{ a: 'label' }], 'a')).toEqual({ label: { a: 'label' } }); +}); diff --git a/test/toggleClass.test.js b/test/toggleClass.test.js index 2ec708391..ed55029ec 100644 --- a/test/toggleClass.test.js +++ b/test/toggleClass.test.js @@ -4,3 +4,9 @@ const {toggleClass} = require('./_30s.js'); test('toggleClass is a Function', () => { expect(toggleClass).toBeInstanceOf(Function); }); +test('toggleClass toggles the class', () => { + let el = document.createElement('div'); + el.classList.add('myClass'); + toggleClass(el, 'myClass'); + expect(el.classList.contains('myClass')).toBeFalsy(); +}); diff --git a/test/triggerEvent.test.js b/test/triggerEvent.test.js index 13df31d08..6b692e432 100644 --- a/test/triggerEvent.test.js +++ b/test/triggerEvent.test.js @@ -4,3 +4,11 @@ const {triggerEvent} = require('./_30s.js'); test('triggerEvent is a Function', () => { expect(triggerEvent).toBeInstanceOf(Function); }); +test('triggerEvent triggers an event', () => { + let el = document.createElement('div'); + let val = false; + const fn = () => val = true; + el.addEventListener('click', fn); + triggerEvent(el, 'click', {}) + expect(val).toBeTruthy(); +}); diff --git a/test/uncurry.test.js b/test/uncurry.test.js index 8e298929a..e3cdcfedb 100644 --- a/test/uncurry.test.js +++ b/test/uncurry.test.js @@ -17,3 +17,8 @@ test('Works with n = 2', () => { test('Works with n = 3', () => { expect(add3(1, 2, 3)).toBe(6); }); +test('Throws RangeError if arguments are too few', () => { + expect(() => { + add2(2); + }).toThrow(RangeError); +});