diff options
author | Cashew <52880648+Scrub1492@users.noreply.github.com> | 2024-01-06 08:00:37 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-06 01:00:37 +0000 |
commit | 60276d41ffd90044acc2f95e70b9b0c9a770417a (patch) | |
tree | 0bd08871a14d025007ba5453691b27976c39d77d /test/cache-map.test.js | |
parent | d17ca4b2ff6e6f359dc5ea72c133f99fb016effd (diff) |
Test updates (#501)
* update tests
* japanese-util updates
* update json-schema tests
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); - } + }); }); } |