From 57c8e31a9a6a9019bccc40c956f732858e46f4f2 Mon Sep 17 00:00:00 2001 From: MariaZ Date: Tue, 20 Sep 2022 13:36:05 +0200 Subject: [PATCH] Fix image import mocking --- jest.config.js | 3 +++ test/components/__snapshots__/stats.spec.js.snap | 2 +- test/components/stats.spec.js | 1 - test/file-mock.js | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 test/file-mock.js diff --git a/jest.config.js b/jest.config.js index 005de92..6fb518f 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,6 +1,9 @@ module.exports = { preset: '@testing-library/react-native', moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'], + moduleNameMapper: { + '\\.(png)$': require.resolve('./test/file-mock.js'), + }, setupFilesAfterEnv: ['./test/jest-setup.js'], transformIgnorePatterns: [ 'node_modules/(?!((jest-)?react-native(-.*)?|@react-native(-community)?)/)', diff --git a/test/components/__snapshots__/stats.spec.js.snap b/test/components/__snapshots__/stats.spec.js.snap index b3aa698..b27ae71 100644 --- a/test/components/__snapshots__/stats.spec.js.snap +++ b/test/components/__snapshots__/stats.spec.js.snap @@ -60,7 +60,7 @@ exports[`Stats screen when provided data, renders stats 1`] = ` } > 'AppHelp') jest.mock('../../components/common/StatsOverview', () => 'StatsOverview') jest.mock('../../components/common/StatsTable', () => 'StatsTable') -jest.mock('../../assets/cycle-icon.png', () => 'image') const mockGetAllCycleLengths = jest .fn() diff --git a/test/file-mock.js b/test/file-mock.js new file mode 100644 index 0000000..3656be8 --- /dev/null +++ b/test/file-mock.js @@ -0,0 +1 @@ +module.exports = 123