From 9b7fb04edbcc7bcfba0a6dc08185b3d51bdcf826 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Tue, 11 Oct 2022 20:37:49 +0200 Subject: [PATCH] test: fix lint warning and simplify test --- test/locales.spec.ts | 58 +++++++++++--------------------------------- 1 file changed, 14 insertions(+), 44 deletions(-) diff --git a/test/locales.spec.ts b/test/locales.spec.ts index 9e290c5a559..4249f94ded1 100644 --- a/test/locales.spec.ts +++ b/test/locales.spec.ts @@ -1,5 +1,4 @@ import { describe, expect, it } from 'vitest'; -import type { LocaleDefinition } from '../src'; import { faker } from '../src'; import allLocales from '../src/locales'; import './vitest-extensions'; @@ -16,50 +15,21 @@ describe('locale', () => { }); }); - for (const [localeName, moduleMap] of Object.entries(allLocales)) { - describe(localeName, () => { - for (const [ - moduleName, - definitionMap, - ] of Object.entries(moduleMap)) { - if (moduleName === 'title' || moduleName === 'separator') { - continue; - } - - describe(moduleName, () => { - for (const [definitionName, entries] of Object.entries( - definitionMap - )) { - describe(definitionName, () => { - function testArraySample(arr: T[]) { - it('should not have duplicate entries', () => { - expect(arr).not.toContainDuplicates(); - }); - } - - if (Array.isArray(entries)) { - testArraySample(entries); - } else if (typeof entries === 'object') { - for (const [key, samples] of Object.entries(entries)) { - if (Array.isArray(samples)) { - describe(key, () => { - testArraySample(samples); - }); - } else { - it('cant be tested', () => { - expect(true).toBe(true); - }); - } - } - } else { - it('needs to be tested', () => { - expect(false).toBe(true); - }); - } - }); - } + function checkLocaleData(data: unknown) { + if (Array.isArray(data)) { + it('should not have duplicate entries', () => { + expect(data).not.toContainDuplicates(); + }); + } else if (typeof data === 'object' && data != null) { + for (const [nestedKey, nestedData] of Object.entries(data)) { + describe(nestedKey, () => { + checkLocaleData(nestedData); }); } - }); + } else { + it.skip(`primitives cannot be tested`); + } } + + checkLocaleData(allLocales); });