Additional tests

This commit is contained in:
Angelos Chalaris
2018-11-10 13:38:34 +02:00
parent 39ff17ae2a
commit f876560845
6 changed files with 45 additions and 3 deletions

View File

@ -1,4 +1,5 @@
const expect = require('expect'); const expect = require('expect');
const { byteSize } = require('./_30s.js');
const Blob = class { const Blob = class {
constructor(s) { constructor(s) {
return { return {
@ -6,7 +7,6 @@ const Blob = class {
}; };
} }
}; };
const byteSize = str => new Blob([str]).size;
test('byteSize is a Function', () => { test('byteSize is a Function', () => {
expect(byteSize).toBeInstanceOf(Function); expect(byteSize).toBeInstanceOf(Function);

View File

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

View File

@ -4,6 +4,11 @@ const {once} = require('./_30s.js');
test('once is a Function', () => { test('once is a Function', () => {
expect(once).toBeInstanceOf(Function); expect(once).toBeInstanceOf(Function);
}); });
test('once is a Function', () => { test('once returns Function', () => {
expect(typeof once(x => 10)).toBe('function'); expect(typeof once(x => 10)).toBe('function');
}); });
test('once returns the result only once', () => {
let onced = once(x => x);
expect(onced(10)).toBe(10);
expect(onced(10)).toBe(undefined);
});

View File

@ -14,3 +14,6 @@ test('Generates all permutations of an array', () => {
[5, 33, 1] [5, 33, 1]
]); ]);
}); });
test('Generates all permutations of an array', () => {
expect(permutations([1])).toEqual([1]);
});

View File

@ -13,9 +13,12 @@ test('Produces the singular of the word', () => {
test('Produces the plural of the word', () => { test('Produces the plural of the word', () => {
expect(pluralize(2, 'apple')).toBe('apples'); expect(pluralize(2, 'apple')).toBe('apples');
}); });
test('Prodices the defined plural of the word', () => { test('Produces the defined plural of the word', () => {
expect(pluralize(2, 'person', 'people')).toBe('people'); expect(pluralize(2, 'person', 'people')).toBe('people');
}); });
test('Produces the defined plural of the word', () => {
expect(pluralize(1, 'person', 'people')).toBe('person');
});
const PLURALS = { const PLURALS = {
person: 'people', person: 'people',
radius: 'radii' radius: 'radii'

View File

@ -13,3 +13,9 @@ test('Converts a number in bytes to a human-readable string.', () => {
test('Converts a number in bytes to a human-readable string.', () => { test('Converts a number in bytes to a human-readable string.', () => {
expect(prettyBytes(123456789, 3, false)).toBe('123MB'); expect(prettyBytes(123456789, 3, false)).toBe('123MB');
}); });
test('Converts a number in bytes to a human-readable string.', () => {
expect(prettyBytes(0, 3, false)).toBe('0B');
});
test('Converts a number in bytes to a human-readable string.', () => {
expect(prettyBytes(0, 3, true)).toBe('0 B');
});