jestjs/jest · error · TypeError

Filter did not return a valid test list

Error message

Filter ${filterPath} did not return a valid test list

What it means

Thrown as a TypeError by SearchSource.getTestPaths when a filter function (configured via globalConfig.filter, pointing to a module exporting a filter function) is invoked and its return value does not have an Array .filtered property. The filter contract requires returning { filtered: string[] }.

Solutions

  1. Make the filter module return { filtered: [...paths] }
  2. If the filter is async, await and then return the wrapped object
  3. Validate the return shape before exporting

Example fix

// before: filter.js
module.exports = (testPaths) => testPaths;

// after
module.exports = (testPaths) => ({
  filtered: testPaths.filter(p => p.includes('unit')),
});
Defensive patterns

Strategy: validation

Validate before calling

function assertFilterResult(result: unknown): asserts result is { filtered: string[] } {
  if (!result || typeof result !== 'object' || !Array.isArray((result as any).filtered)) {
    throw new TypeError('Filter must return { filtered: string[] }');
  }
}

Type guard

function isValidFilterResult(value: unknown): value is { filtered: string[] } {
  return (
    typeof value === 'object' &&
    value !== null &&
    Array.isArray((value as any).filtered) &&
    (value as any).filtered.every((p: unknown) => typeof p === 'string')
  );
}

Prevention

When it happens

Trigger: Writing a --filter module that returns a bare array, an object without 'filtered', undefined, or a promise that resolves to a non-conforming shape.

Common situations: Misunderstanding the filter file contract (developers often return an array of paths directly); partial migrations of filter scripts; async filters that forget to return the wrapped object.

Related errors


AI-assisted analysis of jestjs/jest@8e6d128e4a (2026-08-10). Data as JSON: /api/errors/57ae1318d876d18f. Report an issue: GitHub.

Appendix: source

Thrown at packages/jest-core/src/SearchSource.ts:345

    projectConfig: Config.ProjectConfig,
    changedFiles?: ChangedFiles,
    filter?: Filter,
  ): Promise<SearchResult> {
    const searchResult = await this._getTestPaths(
      globalConfig,
      projectConfig,
      changedFiles,
    );

    const filterPath = globalConfig.filter;

    if (filter) {
      const tests = searchResult.tests;

      const filterResult = await filter(tests.map(test => test.path));

      if (!Array.isArray(filterResult.filtered)) {
        throw new TypeError(
          `Filter ${filterPath} did not return a valid test list`,
        );
      }

      const filteredSet = new Set(filterResult.filtered);

      return {
        ...searchResult,
        tests: tests.filter(test => filteredSet.has(test.path)),
      };
    }

    return searchResult;
  }

  async findRelatedSourcesFromTestsInChangedFiles(
    changedFilesInfo: ChangedFiles,
  ): Promise<Array<string>> {

View on GitHub (pinned to 8e6d128e4a)