aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2022-10-12 13:10:54 +0200
committerGitHub <[email protected]>2022-10-12 13:10:54 +0200
commitaee54a106a37433c2cdb9d7be7c6d22a5ea9fee7 (patch)
treebc22270784c5f20bd04176f61e831cc667d70ada
parentf124bfbcaabef29b2530cdb1ac6ef2e982a5981e (diff)
downloadfaker-aee54a106a37433c2cdb9d7be7c6d22a5ea9fee7.tar.xz
faker-aee54a106a37433c2cdb9d7be7c6d22a5ea9fee7.zip
test: fix lint warning and simplify locales test (#1430)
-rw-r--r--test/locales.spec.ts58
1 files changed, 14 insertions, 44 deletions
diff --git a/test/locales.spec.ts b/test/locales.spec.ts
index 9e290c5a..4249f94d 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<LocaleDefinition>(moduleMap)) {
- if (moduleName === 'title' || moduleName === 'separator') {
- continue;
- }
-
- describe(moduleName, () => {
- for (const [definitionName, entries] of Object.entries(
- definitionMap
- )) {
- describe(definitionName, () => {
- function testArraySample<T>(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);
});