代码拉取完成,页面将自动刷新
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React, { useState } from "react";
import { useEffect } from "react";
import { ScrollView, Text, Button, View } from "react-native";
import { Tester, TestSuite, TestCase } from '@rnoh/testerino';
import {
setJSExceptionHandler,
getJSExceptionHandler,
setNativeExceptionHandler
} from "react-native-exception-handler";
import CheckBox from "@react-native-community/checkbox";
export const ExceptionHandlerDemo1 = () => {
return (
<ScrollView>
<Tester>
<TestCase
itShould="setJSExceptionHandler"
initialState=''
tags={['C_API']}
arrange={({ setState, state }) => {
const nativeCallBack = (errMsg: React.SetStateAction<string>) => {
console.log('aaaa')
};
const errorHandler = (e, isFatal) => {
setGetRequestResult("js 异常 是 e")
console.log(e)
setState(e)
};
setNativeExceptionHandler(nativeCallBack, false);
setJSExceptionHandler(errorHandler, true);
const [getRequestResult, setGetRequestResult] = useState('');
const triggerJSExceptionHandler = () => {
throw new Error("js-error")
}
return (
<View style={{ height: 100, padding: 20 }}>
<Button onPress={() => {
triggerJSExceptionHandler()
}}
title="触发js异常" />
</View>
)
}}
assert={async ({ expect, state }) => {
expect(state).to.be.eq('Error: js-error');
}}
/>
{/* <TestCase
itShould="getJSExceptionHandler"
initialState={true}
tags={['C_API']}
arrange={({ setState, state }) => {
const nativeCallBack = (errMsg: React.SetStateAction<string>) => {
console.log('aaaa')
};
const errorHandler = (e, isFatal) => {
console.log('setErrMsg begin')
console.log(e)
console.log('setErrMsg end')
setGetRequestResult("测试结果")
setState(false)
};
setNativeExceptionHandler(nativeCallBack, false)
setJSExceptionHandler(errorHandler, true)
const [getRequestResult, setGetRequestResult] = useState('');
const GetMothedExample = () => {
throw new Error("js-error")
}
return (
<View style={{ height: 100, padding: 20 }}>
<Button onPress={() => {
GetMothedExample()
}}
title="触发异常" />
</View>
)
}}
assert={async ({ expect, state }) => {
expect(state).to.be.eq(false);
}}
/> */}
<TestCase
itShould="setNativeExceptionHandler"
initialState=''
tags={['C_API']}
arrange={({ setState, state }) => {
const [value, setValue] = useState<boolean>(false)
const [toggleCheckBox, setToggleCheckBox] = useState<boolean>(false)
const nativeCallBack = (errMsg: React.SetStateAction<string>) => {
console.log('aaaa')
};
const errorHandler = (e, isFatal) => {
console.log('setErrMsg begin')
console.log(e)
console.log('setErrMsg end')
setGetRequestResult("测试结果")
setState(false)
};
setNativeExceptionHandler(nativeCallBack, false)
setJSExceptionHandler(errorHandler, true)
const [getRequestResult, setGetRequestResult] = useState('');
const GetMothedExample = () => {
throw new Error("js-error")
}
return (
<View style={{ height: 100, padding: 20 }}>
{state === 'black' ?
<CheckBox
disabled={false}
value={toggleCheckBox}
style={{ width: 70, height: 70 }}
tintColor={"red"}
onCheckColor={"green"}
onChange={(event) => {
setValue(event.nativeEvent.value);
}}
onValueChange={(newValue) => {
setToggleCheckBox(newValue);
}}
/> : <></>}
<Button onPress={() => {
setState('black')
}}
title="触发异常" />
</View>
)
}}
assert={async ({ expect, state }) => {
expect(state).to.be.eq(false);
}}
/>
</Tester>
</ScrollView>)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。