mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-23 20:01:01 +08:00
Asset basenames in Jest snapshots
Summary:
This change only affects tests run with Jest. `require('/images/image1.png')` will be replaced with
```
Object {
"testUri": "relative/path/to/images/image1.png",
}
```
in the Jest snapshot instead of always being 1 returned by RelativeImageStub. This change makes it possible to test conditional asset loading in components.
The problem with this change is that it will probably break a lot of existing snapshots, but that should be easily fixed when a project updates to a new version of React Native by running `jest -u` to update all snapshots.
A component can have conditional asset loading based on its props, this logic would be nice to test with Jest snapshots. This problem has been discussed in https://github.com/facebook/jest/issues/2838.
* **Who does this affect**: Everyone using `Image` in Jest snapshots
* **How to migrate**: Running `jest -u` will update the snapshots, the snapshots should be reviewed that they are correct.
* **Why make this breaking change**: It enables testing of conditional asset loading.
* **Severity (number of people affected x effort)**: Low.
Closes https://github.com/facebook/react-native/pull/13319
Reviewed By: rafeca
Differential Revision: D5708180
Pulled By: mjesun
fbshipit-source-id: 16ac42004d597db08545a21d4fffe95c5ee7e21f
This commit is contained in:
committed by
Facebook Github Bot
parent
ad733ad430
commit
25639176ff
@@ -12,6 +12,7 @@
|
||||
},
|
||||
"jest": {
|
||||
"transform": {
|
||||
"^[./a-zA-Z0-9$_-]+\\.(bmp|gif|jpg|jpeg|png|psd|svg|webp)$": "<rootDir>/jest/assetFileTransformer.js",
|
||||
".*": "./jest/preprocessor.js"
|
||||
},
|
||||
"setupFiles": [
|
||||
@@ -19,8 +20,7 @@
|
||||
],
|
||||
"timers": "fake",
|
||||
"moduleNameMapper": {
|
||||
"^React$": "<rootDir>/Libraries/react-native/React.js",
|
||||
"^[./a-zA-Z0-9$_-]+\\.png$": "RelativeImageStub"
|
||||
"^React$": "<rootDir>/Libraries/react-native/React.js"
|
||||
},
|
||||
"testPathIgnorePatterns": [
|
||||
"Libraries/Renderer",
|
||||
|
||||
Reference in New Issue
Block a user