Fix ImageLoader.getSize jest mock#34653
Conversation
`getSize` should resolve with an array of `[width, height]` but this mock resolves with `{ width, height }`.
|
Hi @elliottkember! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
Base commit: 4e70376 |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Base commit: 4e70376 |
|
@NickGerleman has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
This pull request was successfully merged by @elliottkember in 7be829f. When will my fix make it into a release? | Upcoming Releases |
getSizeshould 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:
but in the jest setup file:
Summary
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:
Changelog
[JavaScript] [Changed]: Changed the mocked return value of
ImageLoader.getSizeto be[320, 240]instead of{ width: 320, height: 240 }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.