diff options
Diffstat (limited to 'test/cache-map.test.js')
-rw-r--r-- | test/cache-map.test.js | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/test/cache-map.test.js b/test/cache-map.test.js index 9db30677..5db35cf0 100644 --- a/test/cache-map.test.js +++ b/test/cache-map.test.js @@ -18,35 +18,27 @@ /* eslint-disable no-multi-spaces */ -import {expect, test} from 'vitest'; +import {describe, expect, test} from 'vitest'; import {CacheMap} from '../ext/js/general/cache-map.js'; /** */ function testConstructor() { - test('constructor', () => { - const data = [ - [false, () => new CacheMap(0)], - [false, () => new CacheMap(1)], - [false, () => new CacheMap(Number.MAX_VALUE)], - [true, () => new CacheMap(-1)], - [true, () => new CacheMap(1.5)], - [true, () => new CacheMap(Number.NaN)], - [true, () => new CacheMap(Number.POSITIVE_INFINITY)] - ]; + describe('constructor', () => { + const shouldThrow = [-1, 1.5, Number.NaN, Number.POSITIVE_INFINITY]; + const shouldNotThrow = [0, 1, Number.MAX_VALUE]; - for (const [throws, create] of data) { - if (throws) { - expect(create).toThrowError(); - } else { - expect(create).not.toThrowError(); - } - } + test.each(shouldNotThrow)('`() => new CacheMap(%d)` should not throw', (param) => { + expect(() => new CacheMap(param)).not.toThrowError(); + }); + test.each(shouldThrow)('`() => new CacheMap(%d)` should throw', (param) => { + expect(() => new CacheMap(param)).toThrowError(); + }); }); } /** */ function testApi() { - test('api', () => { + describe('api', () => { const data = [ { maxSize: 1, @@ -99,7 +91,7 @@ function testApi() { } ]; - for (const {maxSize, expectedSize, calls} of data) { + test.each(data)('api-test-%#', ({maxSize, expectedSize, calls}) => { const cache = new CacheMap(maxSize); expect(cache.maxSize).toStrictEqual(maxSize); for (const call of calls) { @@ -117,7 +109,7 @@ function testApi() { } } expect(cache.size).toStrictEqual(expectedSize); - } + }); }); } |