Nastavení adresáře vlastních snímků Jest

Když chcete umístit testovací soubory komponenty přímo vedle komponent, ale nechcete, aby byly vaše adresáře poseté __snapshots__/ dirs:

// __snapshots__/snapshotResolver.js

module.exports = {
  resolveSnapshotPath: (testPath, snapshotExtension) =>
    testPath
      .replace(
        /\.test\.([tj]sx?)/, 
        `.test${snapshotExtension}`
      )
      .replace(
        /src([/\\]components)/, 
        '__snapshots__'
      ),

  resolveTestPath: (snapshotFilePath, snapshotExtension) =>
    snapshotFilePath
      .replace(snapshotExtension, '.js')
      .replace('__snapshots__', 'src/components'),

  testPathForConsistencyCheck: 'src/components/some.test.js',
}
// jest.config.js

module.exports = {
  preset: 'react-native', // optional depending on your project

  snapshotResolver: './__snapshots__/snapshotResolver.js',

  testMatch: [
    '**/__tests__/**/?(*.)+(spec|test).(js|ts|tsx)', 
    '**/?(*.)+(spec|test).(js|ts|tsx)'
  ],
}