Additional tests
This commit is contained in:
@ -14,7 +14,7 @@ const toHash = (object, key) =>
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```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' } }
|
toHash([{ a: 'label' }], 'a'); // { label: { a: 'label' } }
|
||||||
// A more in depth example:
|
// A more in depth example:
|
||||||
let users = [{ id: 1, first: 'Jon' }, { id: 2, first: 'Joe' }, { id: 3, first: 'Moe' }];
|
let users = [{ id: 1, first: 'Jon' }, { id: 2, first: 'Joe' }, { id: 3, first: 'Moe' }];
|
||||||
|
|||||||
@ -4,3 +4,6 @@ const {bottomVisible} = require('./_30s.js');
|
|||||||
test('bottomVisible is a Function', () => {
|
test('bottomVisible is a Function', () => {
|
||||||
expect(bottomVisible).toBeInstanceOf(Function);
|
expect(bottomVisible).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
|
test('bottomVisible returns a boolean', () => {
|
||||||
|
expect(typeof bottomVisible()).toBe('boolean');
|
||||||
|
});
|
||||||
|
|||||||
@ -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.', () => {
|
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);
|
||||||
});
|
});
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
|||||||
@ -7,3 +7,9 @@ test('sortedIndexBy is a 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)).toBe(0);
|
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);
|
||||||
|
});
|
||||||
|
|||||||
@ -7,3 +7,9 @@ test('sortedLastIndex is a 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)).toBe(4);
|
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);
|
||||||
|
});
|
||||||
|
|||||||
@ -7,3 +7,9 @@ test('sortedLastIndexBy is a 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)).toBe(1);
|
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);
|
||||||
|
});
|
||||||
|
|||||||
@ -4,3 +4,6 @@ const {squareSum} = require('./_30s.js');
|
|||||||
test('squareSum is a Function', () => {
|
test('squareSum is a Function', () => {
|
||||||
expect(squareSum).toBeInstanceOf(Function);
|
expect(squareSum).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
|
test('squareSum returns the proper result', () => {
|
||||||
|
expect(squareSum(2, 3, 4)).toBe(29);
|
||||||
|
});
|
||||||
|
|||||||
@ -4,3 +4,8 @@ const {throttle} = require('./_30s.js');
|
|||||||
test('throttle is a Function', () => {
|
test('throttle is a Function', () => {
|
||||||
expect(throttle).toBeInstanceOf(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);
|
||||||
|
});
|
||||||
|
|||||||
@ -4,3 +4,9 @@ const {toHash} = require('./_30s.js');
|
|||||||
test('toHash is a Function', () => {
|
test('toHash is a Function', () => {
|
||||||
expect(toHash).toBeInstanceOf(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' } });
|
||||||
|
});
|
||||||
|
|||||||
@ -4,3 +4,9 @@ const {toggleClass} = require('./_30s.js');
|
|||||||
test('toggleClass is a Function', () => {
|
test('toggleClass is a Function', () => {
|
||||||
expect(toggleClass).toBeInstanceOf(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();
|
||||||
|
});
|
||||||
|
|||||||
@ -4,3 +4,11 @@ const {triggerEvent} = require('./_30s.js');
|
|||||||
test('triggerEvent is a Function', () => {
|
test('triggerEvent is a Function', () => {
|
||||||
expect(triggerEvent).toBeInstanceOf(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();
|
||||||
|
});
|
||||||
|
|||||||
@ -17,3 +17,8 @@ test('Works with n = 2', () => {
|
|||||||
test('Works with n = 3', () => {
|
test('Works with n = 3', () => {
|
||||||
expect(add3(1, 2, 3)).toBe(6);
|
expect(add3(1, 2, 3)).toBe(6);
|
||||||
});
|
});
|
||||||
|
test('Throws RangeError if arguments are too few', () => {
|
||||||
|
expect(() => {
|
||||||
|
add2(2);
|
||||||
|
}).toThrow(RangeError);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user