-
-
Notifications
You must be signed in to change notification settings - Fork 880
/
locales.spec.ts
35 lines (31 loc) · 1014 Bytes
/
locales.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { describe, expect, it } from 'vitest';
import { faker } from '../src';
import allLocales from '../src/locales';
import './vitest-extensions';
// Remark: actual use of locales functionality is currently tested in all.functional.js test
describe('locale', () => {
describe('setLocale()', () => {
it('setLocale() changes faker.locale', () => {
for (const locale in faker.locales) {
faker.setLocale(locale);
expect(faker.locale).toBe(locale);
}
});
});
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);
});