/
githubmirror
/
pixijs
Обзор
Документация
Войти
/
githubmirror
/
pixijs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
src/assets/cache/__tests__/Cache.test.ts
83 строки
2 KB
Matt Karl
chore: Reorganize tests into more conventional structure (#11126)
04 дек 2024, 23:36
Не верифицирован
04 дек 2024, 23:36
a68e311
Код
Авторство
О чём код?
import { Cache } from '../Cache'; import type { CacheParser } from '../CacheParser'; const testParser = { test: (asset: string) => typeof asset === 'string', getCacheableAssets: (keys: string[], asset: string) => { const out: Record<string, string> = {}; keys.forEach((key) => { out[key] = `${asset}-${key}`; }); return out; } } as CacheParser<string>; describe('Cache', () => { beforeEach(() => { Cache.reset(); (Cache as any)['_parsers'] = []; }); it('should process a custom parsers correctly', () => { Cache['_parsers'].push(testParser); Cache.set('test', 'hello'); const out = Cache.get('test'); expect(out).toBe('hello-test'); }); it('should process multiple keys with a custom parser correctly', () => { Cache['_parsers'].push(testParser); Cache.set(['test', 'chicken'], 'hello'); const out = Cache.get('test'); expect(out).toBe('hello-test'); const chicken = Cache.get('chicken'); expect(chicken).toBe('hello-chicken'); }); it('should remove keys with a custom parsers correctly', () => { Cache['_parsers'].push(testParser); Cache.set('test', 'hello'); Cache.remove('test'); const out = Cache.get('test'); expect(out).toBe(undefined); }); it('should remove multiple keys with a custom parser correctly', () => { Cache['_parsers'].push(testParser); Cache.set(['test', 'chicken'], 'hello'); Cache.remove('test'); const out = Cache.get('test'); expect(out).toBe(undefined); const chicken = Cache.get('chicken'); expect(chicken).toBe(undefined); }); });