aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2023-12-11 19:42:59 +0100
committerGitHub <[email protected]>2023-12-11 18:42:59 +0000
commit1631115a6a9846c50473fe60ea5bdb7ce9d04084 (patch)
tree6b9dcb203e31aea8ff2233ef60046278139ea71b /test
parent60dcfe7c6454327740d2253ed283deb59d420462 (diff)
downloadfaker-1631115a6a9846c50473fe60ea5bdb7ce9d04084.tar.xz
faker-1631115a6a9846c50473fe60ea5bdb7ce9d04084.zip
infra(tsconfig): noImplicitAny (#2562)
Diffstat (limited to 'test')
-rw-r--r--test/all-functional.spec.ts10
-rw-r--r--test/faker.spec.ts3
-rw-r--r--test/locale-imports.spec.ts9
-rw-r--r--test/modules/helpers.spec.ts8
-rw-r--r--test/modules/image.spec.ts2
-rw-r--r--test/simple-faker.spec.ts7
6 files changed, 21 insertions, 18 deletions
diff --git a/test/all-functional.spec.ts b/test/all-functional.spec.ts
index d4b1308a..a883da7d 100644
--- a/test/all-functional.spec.ts
+++ b/test/all-functional.spec.ts
@@ -1,6 +1,7 @@
import { describe, expect, it } from 'vitest';
import type { allLocales, Faker, RandomModule } from '../src';
import { allFakers, fakerEN } from '../src';
+import { keys } from '../src/internal/keys';
const IGNORED_MODULES = new Set([
'rawDefinitions',
@@ -35,11 +36,7 @@ function isTestableModule(moduleName: string): moduleName is keyof Faker {
}
function getMethodNamesOf(module: object): string[] {
- return Object.keys(module).filter(isMethodOf(module));
-}
-
-function isMethodOf(module: object): (method: string) => boolean {
- return (method: string) => typeof module[method] === 'function';
+ return keys(module).filter((method) => typeof module[method] === 'function');
}
type SkipConfig<TModule> = Partial<
@@ -81,6 +78,7 @@ function isWorkingLocaleForMethod(
method: string,
locale: string
): boolean {
+ // @ts-expect-error: We don't have types for the dynamic access
const broken = BROKEN_LOCALE_METHODS[module]?.[method] ?? [];
return broken !== '*' && !broken.includes(locale);
}
@@ -104,6 +102,7 @@ describe('BROKEN_LOCALE_METHODS test', () => {
it('should not contain obsolete configuration (methods)', () => {
const existingMethods = modules[module];
const configuredMethods = Object.keys(
+ // @ts-expect-error: We don't have types for the dynamic access
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
BROKEN_LOCALE_METHODS[module] ?? {}
);
@@ -129,6 +128,7 @@ describe('functional tests', () => {
const testAssertion = () => {
// TODO @ST-DDT 2022-03-28: Use random seed once there are no more failures
faker.seed(1);
+ // @ts-expect-error: We don't have types for the dynamic access
const result = faker[module][meth]();
if (meth === 'boolean') {
diff --git a/test/faker.spec.ts b/test/faker.spec.ts
index a098d898..bf1bfafc 100644
--- a/test/faker.spec.ts
+++ b/test/faker.spec.ts
@@ -2,6 +2,7 @@ import type { SpyInstance } from 'vitest';
import { describe, expect, it, vi } from 'vitest';
import { faker, Faker } from '../src';
import { FakerError } from '../src/errors/faker-error';
+import { keys } from '../src/internal/keys';
describe('faker', () => {
it('should throw error if no locales passed', () => {
@@ -13,7 +14,7 @@ describe('faker', () => {
});
it('should not log anything on startup', () => {
- const spies: SpyInstance[] = Object.keys(console)
+ const spies: SpyInstance[] = keys(console)
.filter((key) => typeof console[key] === 'function')
.map((methodName) =>
vi.spyOn(console, methodName as keyof typeof console)
diff --git a/test/locale-imports.spec.ts b/test/locale-imports.spec.ts
index 999a7223..1d7dc475 100644
--- a/test/locale-imports.spec.ts
+++ b/test/locale-imports.spec.ts
@@ -1,8 +1,9 @@
import { describe, expect, it } from 'vitest';
import type { Faker } from '../src';
import { allLocales } from '../src';
+import { keys } from '../src/internal/keys';
-describe.each(Object.keys(allLocales))('locale imports', (locale) => {
+describe.each(keys(allLocales))('locale imports', (locale) => {
it(`should be possible to directly require('@faker-js/faker/locale/${locale}')`, () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires, unicorn/prefer-module
const { faker } = require(`../dist/cjs/locale/${locale}`) as {
@@ -12,7 +13,7 @@ describe.each(Object.keys(allLocales))('locale imports', (locale) => {
expect(faker).toBeDefined();
expect(faker.string.alpha()).toBeTypeOf('string');
expect(faker.definitions.metadata.title).toBe(
- allLocales[locale].metadata.title
+ allLocales[locale].metadata?.title
);
});
@@ -24,12 +25,12 @@ describe.each(Object.keys(allLocales))('locale imports', (locale) => {
expect(faker).toBeDefined();
expect(faker.string.alpha()).toBeTypeOf('string');
expect(faker.definitions.metadata.title).toBe(
- allLocales[locale].metadata.title
+ allLocales[locale].metadata?.title
);
});
it('should have complete metadata values', () => {
- const metadata = allLocales[locale].metadata;
+ const metadata = allLocales[locale].metadata ?? {};
expect(metadata.title).toBeTypeOf('string');
expect(metadata.code).toBeTypeOf('string');
expect(metadata.code).toEqual(locale);
diff --git a/test/modules/helpers.spec.ts b/test/modules/helpers.spec.ts
index 766d0650..1a1db9c5 100644
--- a/test/modules/helpers.spec.ts
+++ b/test/modules/helpers.spec.ts
@@ -1,6 +1,7 @@
import { describe, expect, it } from 'vitest';
import { faker, FakerError } from '../../src';
import { luhnCheck } from '../../src/modules/helpers/luhn-check';
+import type { RecordKey } from '../../src/modules/helpers/unique';
import { seededTests } from '../support/seeded-runs';
import { times } from './../support/times';
import './../vitest-extensions';
@@ -1295,8 +1296,9 @@ Try adjusting maxTime or maxRetries parameters for faker.helpers.unique().`)
const maxTime = 49;
const maxRetries = 49;
const currentIterations = 0;
- const exclude = [];
- const compare = (obj, key) => (obj[key] === undefined ? -1 : 0);
+ const exclude: string[] = [];
+ const compare = (obj: Record<RecordKey, RecordKey>, key: RecordKey) =>
+ obj[key] === undefined ? -1 : 0;
const options = {
startTime,
@@ -1318,7 +1320,7 @@ Try adjusting maxTime or maxRetries parameters for faker.helpers.unique().`)
});
it('should be possible to pass a user-specific store', () => {
- const store = {};
+ const store: Record<string, string> = {};
const method = () => 'with conflict: 0';
diff --git a/test/modules/image.spec.ts b/test/modules/image.spec.ts
index 938799ef..004905e7 100644
--- a/test/modules/image.spec.ts
+++ b/test/modules/image.spec.ts
@@ -257,7 +257,7 @@ describe('image', () => {
'objects',
'people',
'technology',
- ];
+ ] satisfies Array<keyof typeof faker.image.unsplash>;
describe.each(categories)(`%s()`, (category) => {
it(`should return a random ${category} image url`, () => {
diff --git a/test/simple-faker.spec.ts b/test/simple-faker.spec.ts
index 899bcafe..ec1247cf 100644
--- a/test/simple-faker.spec.ts
+++ b/test/simple-faker.spec.ts
@@ -1,14 +1,13 @@
import type { SpyInstance } from 'vitest';
import { describe, expect, it, vi } from 'vitest';
import { SimpleFaker, simpleFaker } from '../src';
+import { keys } from '../src/internal/keys';
describe('simpleFaker', () => {
it('should not log anything on startup', () => {
- const spies: SpyInstance[] = Object.keys(console)
+ const spies: SpyInstance[] = keys(console)
.filter((key) => typeof console[key] === 'function')
- .map((methodName) =>
- vi.spyOn(console, methodName as keyof typeof console)
- );
+ .map((methodName) => vi.spyOn(console, methodName));
// eslint-disable-next-line @typescript-eslint/no-var-requires, unicorn/prefer-module -- Using import() requires types being build but the CI / TS-Check runs without them.
require('..').simpleFaker;