ihor / react-native-scalable-image

React Native Image component which scales width or height automatically to keep the original aspect ratio
https://www.npmjs.com/package/react-native-scalable-image
MIT License
315 stars 67 forks source link

Running tests with jest generated from react native template #29

Closed atais closed 3 years ago

atais commented 3 years ago

I am trying to run jest tests. I am very new to all react-native environment so it is all quite problematic for me.

Somewhat I think this lib is breaking my test:

npm test

> MyApp@0.0.1 test /home/atais/Documents/lpuradio
> jest

 PASS  __tests__/App-test.js
  ✓ renders correctly (39ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        1.038s
Ran all test suites.

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down.

      at Object.get Image [as Image] (node_modules/react-native/index.js:39:12)
      **at ScalableImage (node_modules/react-native-scalable-image/index.js:23:87)**
      at renderWithHooks (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:5552:18)
      at updateFunctionComponent (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:7499:20)
      at beginWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:9033:16)
  console.error
    Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

    **Check the render method of `ScalableImage`.
        in ScalableImage**
        in View (created by View)
        in View (created by TabBarItem)
        in View (created by View)
        in View (created by TabBarItem)
        in View (created by View)
        in View (created by TabBarItem)
        in View (created by View)
        in View (created by AnimatedComponent)
        in AnimatedComponent (created by ForwardRef(AnimatedComponentWrapper))
        in ForwardRef(AnimatedComponentWrapper) (created by TouchableOpacity)
        in TouchableOpacity (created by ForwardRef)
        in ForwardRef (created by TouchableItem)
        in TouchableItem (created by TabBarItem)
        in TabBarItem (created by TabBar)
        in View (created by View)
        in View (created by ScrollView)
        in RCTScrollView (created by RCTScrollView)
        in RCTScrollView (created by ScrollView)
        in ScrollView (created by ForwardRef)
        in ForwardRef (created by AnimatedComponent)
        in AnimatedComponent (created by ForwardRef(AnimatedComponentWrapper))
        in ForwardRef(AnimatedComponentWrapper) (created by TabBar)
        in View (created by View)
        in View (created by TabBar)
        in View (created by View)
        in View (created by TabBar)
        in TabBar (created by Pager)
        in Pager (created by TabView)
        in View (created by View)
        in View (created by TabView)
        in TabView (created by App)
        in App

      at printWarning (node_modules/react/cjs/react.development.js:315:30)
      at error (node_modules/react/cjs/react.development.js:287:5)
      at Object.createElementWithValidation [as createElement] (node_modules/react/cjs/react.development.js:1788:7)
      at ScalableImage (node_modules/react-native-scalable-image/index.js:35:56)
      at renderWithHooks (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:5552:18)
      at updateFunctionComponent (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:7499:20)
      at beginWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:9033:16)

  console.error
    Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

    ....

aaaand it's all the same couple of times.

I am quite stuck.

atais commented 3 years ago

adding

jest.useFakeTimers()

helped