react-native-macos/jest
Elliott Kember 7be829f2c9 Fix ImageLoader.getSize jest mock (#34653)
Summary:
`getSize` should resolve with an array of `[width, height]` but this mock resolves with `{ width, height }`.

It should be `ReadOnlyArray<number>` instead of `{width: number, height: number}`

The native image loader call is [here](https://github.com/facebook/react-native/blob/main/Libraries/Image/NativeImageLoaderIOS.js#L18):
```js
  +getSize: (uri: string) => Promise<$ReadOnlyArray<number>>;
```

but in the [jest setup file](https://github.com/facebook/react-native/blob/main/jest/setup.js):
```js
  getSize: jest.fn(url => Promise.resolve({width: 320, height: 240})),
```

My tests were failing on `Image.getSize()` - `TypeError: Invalid attempt to destructure non-iterable instance.`

I managed to trace this down to this object being returned by the Jest mock - looks like it's returning a size object instead of a dimensions array.

## Workaround

If you are hitting this issue, you can work around this mock by using:

```js
ReactNative.NativeModules.ImageLoader.getSize = jest.fn((_) => Promise.resolve([320, 240]));
```

## Changelog

[JavaScript] [Changed]: Changed the mocked return value of `ImageLoader.getSize` to be `[320, 240]` instead of `{ width: 320, height: 240 }`

Pull Request resolved: https://github.com/facebook/react-native/pull/34653

Test Plan: TBD? I think a test with `Image.getSize(path)` will cover it. That's where I hit the error with the ios-specific imageLoader's getSize method.

Reviewed By: robhogan

Differential Revision: D39413522

Pulled By: NickGerleman

fbshipit-source-id: 7f18d7acde0cf94da0b4aec8fe2d0cad3fb0cc55
2022-09-12 14:11:28 -07:00
..
private Remove babel plugins from jest preprocessor which are part of preset 2022-05-12 03:48:24 -07:00
MockNativeMethods.js Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
assetFileTransformer.js fix(jest): make assetFileTransformer return an object (#33756) 2022-06-17 10:27:47 -07:00
mockComponent.js Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
mockModal.js fix(jest/setup): fix circular dependencies in mockModal (#32964) 2022-01-26 23:54:55 -08:00
mockNativeComponent.js Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
mockScrollView.js Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
renderer.js Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
setup.js Fix ImageLoader.getSize jest mock (#34653) 2022-09-12 14:11:28 -07:00