Fixture not found: test data file missing
Quick summary
Your test tries to load a fixture file but the file is not found at the specified path.
Why this happens
The fixture file path is incorrect or uses the wrong relative base directory
The fixture file was not created or was deleted but the test still references it
The test runner changes the working directory, making relative paths resolve incorrectly
Minimal example
test('parses config', () => {
const config = fs.readFileSync('fixtures/config.json', 'utf8'); // ENOENT — file not found
expect(JSON.parse(config).port).toBe(3000);
});import path from 'path';
test('parses config', () => {
const config = fs.readFileSync(path.join(__dirname, 'fixtures', 'config.json'), 'utf8');
expect(JSON.parse(config).port).toBe(3000);
});Using __dirname to resolve the fixture path relative to the test file ensures the file is found regardless of the working directory.
How to diagnose
Print the resolved absolute path of the fixture to verify it points to the right location
Check if the fixture file exists with fs.existsSync or a directory listing
Review the test runner configuration for working directory settings
How to fix
Correct the fixture path or use an absolute path resolved from the project root
Create the missing fixture file with the expected test data
Use the test framework's fixture API that resolves paths relative to the test file
How to prevent
Use the test framework's built-in fixture loading API to handle path resolution
Store fixtures in a well-known directory and reference them with consistent path helpers
Related Resources
Related Glossary
Related Lessons
- Test Fixtures
Learn about fixtures.