picker icon indicating copy to clipboard operation
picker copied to clipboard

Jest setup

Open Alaa-Ben opened this issue 2 years ago • 2 comments

Hi ! Are there any guides about how to setup this with jest ? A simple example with Picker causes the following error:

    Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
    
    Check the render method of `Picker`.

I figured this happens because in my setup file, I mock the platform (for other tests purposes):

jest.mock('react-native/Libraries/Utilities/Platform', () => {
  const platform = jest.requireActual('react-native/Libraries/Utilities/Platform')
  return {
    ...platform,
    OS: 'android',
    constants: {
      ...platform.constants,
      reactNativeVersion: {
        major: 0,
        minor: 70,
        patch: 6
      }
    }
  }
})

Any ideas ?

EDIT: I had to put Platform.OS = 'ios' before the render in my test file for this to work. Still means there's an issue with Platform=android & jest :/

Alaa-Ben avatar Dec 21 '22 09:12 Alaa-Ben

same here testing simulating android platform 😢

alextorres94 avatar Mar 22 '23 16:03 alextorres94

Same issue on android platform

huynhnhutlam avatar May 15 '23 04:05 huynhnhutlam