diff --git a/TestCpp.tsx b/TestCpp.tsx index 475fcae74a8a6d7645dbc671484c932416c9f9a9..1a352c932682abde9d95d3ab03e288de2e5868f4 100644 --- a/TestCpp.tsx +++ b/TestCpp.tsx @@ -171,6 +171,7 @@ export const testData: TestResult[] = [ { name: 'NitroModules.isHybridObject(testObject) to be true', state: '⏳ Click to run', message: '' }, { name: 'NitroModules.hasHybridObject(testObject.name) to be true', state: '⏳ Click to run', message: '' }, { name: 'NitroModules.buildType holds a string', state: '⏳ Click to run', message: '' }, + { name: 'createInternalObject() returns SomeExternalObject', state: '⏳ Click to run', message: '' }, ]; const getResult = (state: string) => { @@ -262,6 +263,8 @@ async function getFunc(name: TestResult['name']) { return NitroModulesHasHybridObject(name); case 'NitroModules.buildType holds a string': return NitroModulesBuildType(name); + case 'createInternalObject() returns SomeExternalObject': + return createInternalObjectTest(name); } } @@ -928,6 +931,38 @@ function NitroModulesBuildType(prop: TestResult['name']) { return message } +function createInternalObjectTest(prop: TestResult['name']) { + let message: ResultMessage; + try { + const testObject = NitroModules.createHybridObject("TestObjectCpp"); + + // 调用createInternalObject方法 + const result = testObject.createInternalObject(); + + // 检查返回值是否为对象 + if (typeof result !== 'object' || result === null) { + throw new Error(`Expected SomeExternalObject but got ${typeof result}`); + } + + // 检查是否包含getValue方法(SomeExternalObject的核心方法) + if (!('getValue' in result) || typeof result.getValue !== 'function') { + throw new Error('Expected SomeExternalObject to have getValue method'); + } + + // 调用getValue方法验证功能 + const value = result.getValue(); + if (typeof value !== 'string') { + throw new Error(`Expected getValue() to return string but got ${typeof value}`); + } + + message = resMessage("pass", ""); + + } catch (error) { + message = resMessage("failed", error.message); + } + return message; +} + // 点击调用,更新data export async function upTestData(index: number, testData: TestResult[]) {