diff --git a/test/byteSize.test.js b/test/byteSize.test.js index 1199b5a3b..963aada9f 100644 --- a/test/byteSize.test.js +++ b/test/byteSize.test.js @@ -1,4 +1,5 @@ const expect = require('expect'); +const { byteSize } = require('./_30s.js'); const Blob = class { constructor(s) { return { @@ -6,7 +7,6 @@ const Blob = class { }; } }; -const byteSize = str => new Blob([str]).size; test('byteSize is a Function', () => { expect(byteSize).toBeInstanceOf(Function); diff --git a/test/copyToClipboard.test.js b/test/copyToClipboard.test.js index 27bbd402e..e9b66c361 100644 --- a/test/copyToClipboard.test.js +++ b/test/copyToClipboard.test.js @@ -4,3 +4,28 @@ const {copyToClipboard} = require('./_30s.js'); test('copyToClipboard is a 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); +}); diff --git a/test/once.test.js b/test/once.test.js index 158d164f8..1dd65d3a6 100644 --- a/test/once.test.js +++ b/test/once.test.js @@ -4,6 +4,11 @@ const {once} = require('./_30s.js'); test('once is a Function', () => { expect(once).toBeInstanceOf(Function); }); -test('once is a Function', () => { +test('once returns 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); +}); diff --git a/test/permutations.test.js b/test/permutations.test.js index f0d8764ab..dc92a0232 100644 --- a/test/permutations.test.js +++ b/test/permutations.test.js @@ -14,3 +14,6 @@ test('Generates all permutations of an array', () => { [5, 33, 1] ]); }); +test('Generates all permutations of an array', () => { + expect(permutations([1])).toEqual([1]); +}); diff --git a/test/pluralize.test.js b/test/pluralize.test.js index 0dbe882cd..e732b500e 100644 --- a/test/pluralize.test.js +++ b/test/pluralize.test.js @@ -13,9 +13,12 @@ test('Produces the singular of the word', () => { test('Produces the plural of the word', () => { 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'); }); +test('Produces the defined plural of the word', () => { + expect(pluralize(1, 'person', 'people')).toBe('person'); +}); const PLURALS = { person: 'people', radius: 'radii' diff --git a/test/prettyBytes.test.js b/test/prettyBytes.test.js index 954713d42..76fde2e88 100644 --- a/test/prettyBytes.test.js +++ b/test/prettyBytes.test.js @@ -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.', () => { 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'); +});