as

Settings
Sign out
Notifications
Alexa
亚马逊应用商店
Ring
AWS
文档
Support
Contact Us
My Cases
新手入门
设计和开发
应用发布
参考
支持
跳转到主要内容

6.1 Update jest.config.js

The transformIgnorePatterns must include @amazon-devices/react-native-kepler. Some 4.0.x versions of the package, such as 4.0.1, use ES module syntax in their jest/setup.js file. Without this pattern, Jest fails with SyntaxError: Cannot use import statement outside a module. Use the same Jest configuration as the Vega app template. The template uses the @amazon-devices/react-native-kepler preset and maps react-native imports to @amazon-devices/react-native-kepler, as shown in the following example.
The mocks in jest.setup.js use react-native/Libraries/... paths, such as react-native/Libraries/Utilities/PixelRatio. The moduleNameMapper resolves these paths to the matching modules in @amazon-devices/react-native-kepler, so you don’t need to change them. If your project already has a jest.config.json file from the template, add setupFilesAfterEnv to it instead of creating a jest.config.js file.

6.2 Create jest.setup.js for TV mocks

RN 0.83 changes how mocks work in the test environment. Create a setup file with TV-appropriate mocks, such as the example below.

6.3 Fix Jest mocks for .default exports

RN 0.83 changes many internal modules to use export default. Existing Jest mocks that return plain objects without a .default property break silently, where components receive undefined at runtime. Symptom Cannot read properties of undefined (reading 'create') across multiple test suites. Affected modules
  • react-native/Libraries/StyleSheet/StyleSheet
  • react-native/Libraries/StyleSheet/flattenStyle
  • react-native/Libraries/EventEmitter/NativeEventEmitter
  • react-native/Libraries/Utilities/Platform
  • react-native/Libraries/Utilities/Dimensions
  • react-native/Libraries/Utilities/PixelRatio
  • react-native/Libraries/Utilities/useWindowDimensions
  • react-native/Libraries/BatchedBridge/NativeModules
Fix pattern for object-type exports
Fix pattern for function-type exports:

6.4 Update test files with act() wrapping

React 19 requires state updates in tests to be wrapped in act(), such as the example below.
@testing-library/react-native If you use @testing-library/react-native, the testing library handles act() internally. Don’t wrap render() in ReactTestRenderer.act() because this causes “Can’t access .root on unmounted test renderer” errors.

6.5 Fix navigation stack timer leaks

If you use react-navigation__stack, its Card.tsx file uses animation setTimeout callbacks that fire after Jest tears down the test environment. Symptom You are trying to import a file after the Jest environment has been torn down Fix: add to affected test files

6.6 Fix isolatedModules type export errors

If TypeScript reports TS1205: Re-exporting a type when 'isolatedModules' is enabled requires using 'export type', update your export type like the example below.

6.7 Update snapshots

After all test fixes, regenerate snapshots.
Review changes. Expected React 19 snapshot differences include:
  • Component wrapper structure changes
  • Attribute ordering differences
  • Text node rendering modifications
  • Async boundary updates
Use git diff to review snapshot changes before committing.
最后修改于 2026年10月28日