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
- Make the filter module return { filtered: [...paths] }
- If the filter is async, await and then return the wrapped object
- 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
- Document the { filtered: string[] } contract at the top of your filter module
- Add a unit test asserting the filter returns the wrapped shape
- For async filters, ensure the returned (not awaited) value is still wrapped
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
- file must export a function at
- Changed files must be set when running with -o.
- Can't find a root directory while resolving a config file…
- Cannot find `global.gc` function. Please run node with…
- "cwd" must be an absolute path. cwd
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)