From 1688f7cdb0d4ef2012453b579d69e3485f92f997 Mon Sep 17 00:00:00 2001 From: dorianvp Date: Wed, 12 Feb 2025 01:47:19 -0300 Subject: [PATCH] tests(scanner): Update Jest snapshot file for `react-native-vision-camera` --- __mocks__/react-native-vision-camera.js | 21 +++++++++++++++++++ .../__snapshots__/Scanner.snapshot.tsx.snap | 4 +--- metro.config.js | 13 +++++++++++- 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 __mocks__/react-native-vision-camera.js diff --git a/__mocks__/react-native-vision-camera.js b/__mocks__/react-native-vision-camera.js new file mode 100644 index 000000000..86281404d --- /dev/null +++ b/__mocks__/react-native-vision-camera.js @@ -0,0 +1,21 @@ +// Simple mock for Camera +export const Camera = () => null; + +// Mock that returns a mocked camera object +export const useCameraDevice = jest.fn(() => ({ + id: 'mocked-camera', + name: 'Mock Camera', + position: 'back', +})); + +// Mock that returns permission status and a request function +export const useCameraPermission = jest.fn(() => ({ + hasPermission: true, + requestPermission: jest.fn(), +})); + +// Mock that provides a mocked scanner function +export const useCodeScanner = jest.fn(() => ({ + codeTypes: ['qr', 'ean-13'], + onCodeScanned: jest.fn(), +})); diff --git a/__tests__/__snapshots__/Scanner.snapshot.tsx.snap b/__tests__/__snapshots__/Scanner.snapshot.tsx.snap index ae71c7c0f..fd5313a76 100644 --- a/__tests__/__snapshots__/Scanner.snapshot.tsx.snap +++ b/__tests__/__snapshots__/Scanner.snapshot.tsx.snap @@ -8,7 +8,5 @@ exports[`Component Scanner - test Scanner - snapshot 1`] = ` "width": "100%", } } -> - - +/> `; diff --git a/metro.config.js b/metro.config.js index 72fcb3cbf..19ddd7d93 100644 --- a/metro.config.js +++ b/metro.config.js @@ -1,11 +1,22 @@ const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config'); +const { resolver: defaultResolver } = getDefaultConfig.getDefaultValues(); + /** * Metro configuration * https://reactnative.dev/docs/metro * * @type {import('metro-config').MetroConfig} */ -const config = {}; + +/** + * See https://react-native-vision-camera.com/docs/guides/mocking for more information. + */ +const config = { + resolver: { + ...defaultResolver, + sourceExts: [process.env.RN_SRC_EXT && process.env.RN_SRC_EXT.split(','), ...defaultResolver.sourceExts], + }, +}; module.exports = mergeConfig(getDefaultConfig(__dirname), config);