Description
Using the Image.getSize method in a test when using the jest-preset throws the following exception:
● Foo › something
TypeError: Cannot read property 'then' of undefined
6 | const MyComponent = () => {
7 | useEffect(() => {
> 8 | Image.getSize('uri', (width, height) => {
| ^
9 | console.log({width, height})
10 | })
11 | }, [])
at Function.getSize (node_modules/react-native/Libraries/Image/Image.ios.js:32:36)
at screens/File.test.tsx:8:15
at commitHookEffectListMount (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:12932:26)
at commitPassiveMountOnFiber (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:14346:11)
at commitPassiveMountEffects_complete (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:14306:9)
at commitPassiveMountEffects_begin (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:14293:7)
at commitPassiveMountEffects (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:14281:3)
at flushPassiveEffectsImpl (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:16233:3)
at flushPassiveEffects (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:16182:14)
at node_modules/react-test-renderer/cjs/react-test-renderer.development.js:16002:9
● Foo › something
TypeError: success is not a function
at node_modules/jest-expo/src/preset/setup.js:23:63
Version
0.70.5
Output of npx react-native info
System:
OS: macOS 13.0.1
CPU: (10) arm64 Apple M1 Max
Memory: 471.44 MB / 32.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 14.18.2 - ~/.nvm/versions/node/v14.18.2/bin/node
Yarn: 1.22.19 - /opt/homebrew/bin/yarn
npm: 6.14.15 - ~/.nvm/versions/node/v14.18.2/bin/npm
Watchman: Not Found
Managers:
CocoaPods: 1.11.3 - /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1
Android SDK: Not Found
IDEs:
Android Studio: 2021.3 AI-213.7172.25.2113.9123335
Xcode: 14.1/14B47b - /usr/bin/xcodebuild
Languages:
Java: Not Found
npmPackages:
@react-native-community/cli: Not Found
react: 18.1.0 => 18.1.0
react-native: 0.70.5 => 0.70.5
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found
Steps to reproduce
This issue was actually identified in an expo based project, and was logged here. I was notified that the underlying cause is the stock react-native preset. So I'm simply pasting the repro steps from the original issue.
- Create a blank expo project via
expo-cli --init - Select the tabs template so that the important dependencies are pre-installed
- This installs jest-expo@47.0.1, which seems to have the issue
- Run
yarn add @testing-library/jest-native @testing-library/react-native @types/jest jest-transform-stub -D- Just needed for writing the quick demo test
- Add the test file shared in the "code example" section
- Run it via
yarn jest
Snack, code example, screenshot, or link to a repository
Pasting the same snippet as the one in the original Expo issue
import{useEffect}from"react"import{Image}from"react-native"import{render}from'@testing-library/react-native';constMyComponent=()=>{useEffect(()=>{Image.getSize('uri',(width,height)=>{console.log({width, height})})},[])returnnull}describe('Foo',()=>{it('something',()=>{render(<MyComponent/>)})})
Description
Using the
Image.getSizemethod in a test when using the jest-preset throws the following exception:Version
0.70.5
Output of
npx react-native infoSystem:
OS: macOS 13.0.1
CPU: (10) arm64 Apple M1 Max
Memory: 471.44 MB / 32.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 14.18.2 - ~/.nvm/versions/node/v14.18.2/bin/node
Yarn: 1.22.19 - /opt/homebrew/bin/yarn
npm: 6.14.15 - ~/.nvm/versions/node/v14.18.2/bin/npm
Watchman: Not Found
Managers:
CocoaPods: 1.11.3 - /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1
Android SDK: Not Found
IDEs:
Android Studio: 2021.3 AI-213.7172.25.2113.9123335
Xcode: 14.1/14B47b - /usr/bin/xcodebuild
Languages:
Java: Not Found
npmPackages:
@react-native-community/cli: Not Found
react: 18.1.0 => 18.1.0
react-native: 0.70.5 => 0.70.5
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found
Steps to reproduce
This issue was actually identified in an expo based project, and was logged here. I was notified that the underlying cause is the stock react-native preset. So I'm simply pasting the repro steps from the original issue.
expo-cli --inityarn add @testing-library/jest-native @testing-library/react-native @types/jest jest-transform-stub -Dyarn jestSnack, code example, screenshot, or link to a repository
Pasting the same snippet as the one in the original Expo issue