mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix assert cxx example crash the app when tap Run all tests (#41521)
Summary: When I tap the `Run all tests` button in CxxModuleExample, App crashed because our `assert` examples directoly.  I moved the error report examples to individual section so `Run all tests` not crash.  ## Changelog: [INTERNAL] [FIXED] - [RN-Tester] Fix assert cxx example crash the app when tap `Run all tests` Pull Request resolved: https://github.com/facebook/react-native/pull/41521 Test Plan: None. Reviewed By: christophpurrer Differential Revision: D51423538 Pulled By: rshest fbshipit-source-id: 1e2844aa9011de4476ec4b134d43daa3260a73d5
This commit is contained in:
committed by
Facebook GitHub Bot
parent
1204696f08
commit
02bb50d9ce
@@ -55,7 +55,9 @@ type Examples =
|
||||
| 'rejectPromise'
|
||||
| 'voidFunc'
|
||||
| 'optionalArgs'
|
||||
| 'emitDeviceEvent'
|
||||
| 'emitDeviceEvent';
|
||||
|
||||
type ErrorExamples =
|
||||
| 'voidFuncThrows'
|
||||
| 'getObjectThrows'
|
||||
| 'promiseThrows'
|
||||
@@ -131,6 +133,10 @@ class NativeCxxModuleExampleExample extends React.Component<{||}, State> {
|
||||
});
|
||||
NativeCxxModuleExample?.emitCustomDeviceEvent(CUSTOM_EVENT_TYPE);
|
||||
},
|
||||
};
|
||||
|
||||
// $FlowFixMe[missing-local-annot]
|
||||
_errorTests = {
|
||||
voidFuncThrows: () => {
|
||||
try {
|
||||
NativeCxxModuleExample?.voidFuncThrows();
|
||||
@@ -202,7 +208,7 @@ class NativeCxxModuleExampleExample extends React.Component<{||}, State> {
|
||||
}));
|
||||
}
|
||||
|
||||
_renderResult(name: Examples): React.Node {
|
||||
_renderResult(name: Examples | ErrorExamples): React.Node {
|
||||
const result = this.state.testResults[name] || {};
|
||||
return (
|
||||
<View style={styles.result}>
|
||||
@@ -231,7 +237,7 @@ class NativeCxxModuleExampleExample extends React.Component<{||}, State> {
|
||||
this._setResult(item, this._tests[item]()),
|
||||
)
|
||||
}>
|
||||
<Text style={styles.buttonTextLarge}>Run all tests</Text>
|
||||
<Text style={styles.buttonTextLarge}>Run function call tests</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity
|
||||
onPress={() => this.setState({testResults: {}})}
|
||||
@@ -254,6 +260,24 @@ class NativeCxxModuleExampleExample extends React.Component<{||}, State> {
|
||||
</View>
|
||||
)}
|
||||
/>
|
||||
<View style={styles.item}>
|
||||
<Text style={styles.buttonTextLarge}>Report errors tests</Text>
|
||||
</View>
|
||||
<FlatList
|
||||
// $FlowFixMe[incompatible-type-arg]
|
||||
data={Object.keys(this._errorTests)}
|
||||
keyExtractor={item => item}
|
||||
renderItem={({item}: {item: ErrorExamples, ...}) => (
|
||||
<View style={styles.item}>
|
||||
<TouchableOpacity
|
||||
style={[styles.column, styles.button]}
|
||||
onPress={e => this._setResult(item, this._errorTests[item]())}>
|
||||
<Text style={styles.buttonText}>{item}</Text>
|
||||
</TouchableOpacity>
|
||||
<View style={[styles.column]}>{this._renderResult(item)}</View>
|
||||
</View>
|
||||
)}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user