diff --git a/packages/rn-tester/js/examples/TurboModule/NativeCxxModuleExampleExample.js b/packages/rn-tester/js/examples/TurboModule/NativeCxxModuleExampleExample.js index 5b242bf63a6..e5eddd33e42 100644 --- a/packages/rn-tester/js/examples/TurboModule/NativeCxxModuleExampleExample.js +++ b/packages/rn-tester/js/examples/TurboModule/NativeCxxModuleExampleExample.js @@ -38,6 +38,7 @@ type State = {| type Examples = | 'callback' + | 'callbackWithSubscription' | 'getArray' | 'getBool' | 'getConstants' @@ -221,7 +222,7 @@ class NativeCxxModuleExampleExample extends React.Component<{||}, State> { }; _setResult( - name: string | Examples, + name: Examples | ErrorExamples, result: | $FlowFixMe | void @@ -271,6 +272,7 @@ class NativeCxxModuleExampleExample extends React.Component<{||}, State> { style={[styles.column, styles.button]} onPress={() => Object.keys(this._tests).forEach(item => + // $FlowFixMe this._setResult(item, this._tests[item]()), ) }> diff --git a/packages/rn-tester/js/examples/TurboModule/SampleTurboModuleExample.js b/packages/rn-tester/js/examples/TurboModule/SampleTurboModuleExample.js index 7e3a979ec5b..cd37801b055 100644 --- a/packages/rn-tester/js/examples/TurboModule/SampleTurboModuleExample.js +++ b/packages/rn-tester/js/examples/TurboModule/SampleTurboModuleExample.js @@ -33,6 +33,39 @@ type State = {| }, |}; +type Examples = + | 'callback' + | 'getArray' + | 'getBool' + | 'getConstants' + | 'getCustomEnum' + | 'getCustomHostObject' + | 'getBinaryTreeNode' + | 'getGraphNode' + | 'getNumEnum' + | 'getStrEnum' + | 'getMap' + | 'getNumber' + | 'getObject' + | 'getSet' + | 'getString' + | 'getUnion' + | 'getValue' + | 'promise' + | 'rejectPromise' + | 'voidFunc' + | 'setMenuItem' + | 'optionalArgs' + | 'emitDeviceEvent'; + +type ErrorExamples = + | 'voidFuncThrows' + | 'getObjectThrows' + | 'promiseThrows' + | 'voidFuncAssert' + | 'getObjectAssert' + | 'promiseAssert'; + class SampleTurboModuleExample extends React.Component<{||}, State> { static contextType: React$Context = RootTagContext; @@ -55,7 +88,6 @@ class SampleTurboModuleExample extends React.Component<{||}, State> { NativeSampleTurboModule.getValueWithPromise(true) .then(() => {}) .catch(e => { - console.error(e); this._setResult('rejectPromise', e.message); }), getConstants: () => NativeSampleTurboModule.getConstants(), @@ -80,6 +112,10 @@ class SampleTurboModuleExample extends React.Component<{||}, State> { getRootTag: () => NativeSampleTurboModule.getRootTag(this.context), getValue: () => NativeSampleTurboModule.getValue(5, 'test', {a: 1, b: 'foo'}), + }; + + // $FlowFixMe[missing-local-annot] + _errorTests = { voidFuncThrows: () => { try { NativeSampleTurboModule.voidFuncThrows?.(); @@ -101,7 +137,6 @@ class SampleTurboModuleExample extends React.Component<{||}, State> { .then(() => {}) .catch(e => { console.error(e); - this._setResult('promiseThrows', e.message); }); }, voidFuncAssert: () => { @@ -125,34 +160,12 @@ class SampleTurboModuleExample extends React.Component<{||}, State> { .then(() => {}) .catch(e => { console.error(e); - this._setResult('promiseAssert', e.message); }); }, }; _setResult( - name: - | string - | 'callback' - | 'getArray' - | 'getBool' - | 'getEnum' - | 'getConstants' - | 'getNumber' - | 'getObject' - | 'getRootTag' - | 'getString' - | 'getUnsafeObject' - | 'getValue' - | 'promise' - | 'rejectPromise' - | 'voidFunc' - | 'voidFuncThrows' - | 'getObjectThrows' - | 'promiseThrows' - | 'voidFuncAssert' - | 'getObjectAssert' - | 'promiseAssert', + name: Examples | ErrorExamples, result: | $FlowFixMe | void @@ -204,6 +217,7 @@ class SampleTurboModuleExample extends React.Component<{||}, State> { style={[styles.column, styles.button]} onPress={() => Object.keys(this._tests).forEach(item => + // $FlowFixMe[incompatible-call] this._setResult(item, this._tests[item]()), ) }> @@ -216,9 +230,10 @@ class SampleTurboModuleExample extends React.Component<{||}, State> { item} - renderItem={({item}) => ( + renderItem={({item}: {item: Examples, ...}) => ( { )} /> + + Report errors tests + + item} + renderItem={({item}: {item: ErrorExamples, ...}) => ( + + this._setResult(item, this._errorTests[item]())}> + {item} + + {this._renderResult(item)} + + )} + /> ); }