Additional tests

This commit is contained in:
Angelos Chalaris
2018-11-10 13:04:37 +02:00
parent 7e22b3fae9
commit 39ff17ae2a
12 changed files with 58 additions and 1 deletions

View File

@ -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' }];

View File

@ -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');
});

View File

@ -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);
});

View File

@ -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);
});

View File

@ -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);
});

View File

@ -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);
});

View File

@ -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);
});

View File

@ -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);
});

View File

@ -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' } });
});

View File

@ -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();
});

View File

@ -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();
});

View File

@ -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);
});