Skip to content

test: add type tests for the public API - #16

Merged
milamer merged 1 commit into
mainfrom
test/public-api-types
Nov 9, 2026
Merged

milamer merged 1 commit into
mainfrom
test/public-api-types

Conversation

@milamer

@milamer milamer commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Adds src/__tests__/types.test-d.ts: expectTypeOf assertions for the public API, checked by npm run typecheck (tsconfig includes src). No change to src/ or the package; test: doesn't release.

What is covered

  • parseFormData
    • parameter 0 is Iterable<[path: string, value: string | File]>, parameter 1 is ParseFormDataOptions | undefined
    • accepts FormData, URLSearchParams, [['a', 'x']], and entries with a native File value
    • rejects entries with a number or Blob value (@ts-expect-error)
    • returns an object of JSON values and Files
  • ParseFormDataOptions: exact type (removeEmptyString, depth, transformEntry(entry, defaultTransform) => {path, value}), and a transformEntry that calls defaultTransform compiles
  • A transformEntry that returns a Date must not compile (@ts-expect-error). This is the known limitation behind [Feature request]: Add date-string to date parsing flag #3; if a later change allows it, this test fails and has to be updated on purpose.
  • Every error class (DuplicateKeyError, MixedArrayError, ForbiddenKeyError, DepthLimitError, InvalidPathError): constructor takes [key: string], extends Error, key: string, name: string

The expected types are written out in the test file instead of imported from src/types.ts, so a change to the exported types fails the tests.

Config change: vitest.config.mts

vitest's include (src/**/__tests__/**/*.ts) matched the new file and ran it as 13 runtime tests. At runtime every expectTypeOf call is a no-op, so those tests always pass without checking anything. The file is now excluded (src/**/*.test-d.ts); vitest's typecheck mode isn't needed because tsc already checks it.

No other config changes needed:

  • knip: its vitest plugin already treats *.test-d.ts as entry files, so the file isn't reported.
  • coverage: src/**/__tests__/** is already excluded.
  • oxlint: expectTypeOf is already in vitest/expect-expect's assertFunctionNames.

Checked that the tests can fail

Temporarily changed src/ (then restored) and ran npm run typecheck:

  • depth?: number | string in ParseFormDataOptions → the options test fails
  • | Date added to JsonValue → the return type test fails and the Date @ts-expect-error becomes unused
  • key: string | number in DuplicateKeyError → its key test fails

Also, replacing the rejected number value with a string makes its @ts-expect-error unused, so the rejection tests aren't passing for an unrelated reason.

npm run validate passes.

Add src/__tests__/types.test-d.ts with expectTypeOf assertions for
parseFormData (parameters, accepted inputs including native File
values, return type), ParseFormDataOptions (removeEmptyString, depth,
transformEntry signature) and the error classes. A transformEntry that
returns a Date must not compile (issue #3).

npm run typecheck checks the file. Exclude *.test-d.ts from vitest's
runtime run: its include pattern matched the file, and at runtime every
expectTypeOf call is a no-op, so the tests passed without checking
anything.
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (cd88e9e) to head (59c8818).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #16   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            4         4           
  Lines          134       134           
  Branches        45        45           
=========================================
  Hits           134       134           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@milamer
milamer merged commit 37e9d29 into main Nov 9, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants