1 Star 0 Fork 0

pangyinqiang/testGit4

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ExceptionHandlerDemo.tsx 6.60 KB
一键复制 编辑 原始数据 按行查看 历史
pangyinqiang 提交于 2024-08-15 18:25 +08:00 . 1
/**
* 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>)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/pang-yinqiang/test-git4.git
git@gitee.com:pang-yinqiang/test-git4.git
pang-yinqiang
test-git4
testGit4
master

搜索帮助