add testcase for arrow callback

Signed-off-by: zhaojunxia <zhaojunxia@kaihong.com>
This commit is contained in:
zhaojunxia 2023-10-30 18:56:35 -07:00
parent 603f953059
commit 2d1df115cc
3 changed files with 19 additions and 4 deletions

View File

@ -48,9 +48,9 @@ napi_value [middleClassName][funcName]_middle(napi_env env, napi_callback_info i
napi_value args[ARGS_SIZE];
[valuePackage]
{
// 回调为参数个数为1其转换结果保存在result中
// 回调箭头函数支持参数个数大于1参数转换结果保存在args[i]
if (ARGS_SIZE == XNapiTool::ONE) {
// 回调为Callback<XX>参数个数为1其转换结果保存在result中
// 回调箭头函数支持参数个数大于1参数转换结果保存在args[i]
if (ARGS_SIZE == XNapiTool::ONE && result != nullptr) {
args[0] = result;
}
retVal = pxt->SyncCallBack(pxt->GetArgv([callback_param_offset]), ARGS_SIZE, args);

View File

@ -74,7 +74,7 @@ declare namespace napitest {
// function fun23nm(cb: (wid: boolean) => TestClass2): string; // 待支持
// function fun24nm(cb: (wid: boolean) => Human): string; // 待支持
// 以下测试用例待支持
// // 以下测试用例待支持
function fun9(cb: (wid: boolean, str: string, tc2:number) => string): string;

View File

@ -43,6 +43,14 @@ function onCallbackVoid () {
}
function onCallbackBooleanVStr (isOK) {
let str
if (isOK) {
str = 'a' + 'b'
}
// return 'test aaa'
}
describe('Test interface callback', function () {
// fun11(cb: Callback<number>): void;
it('test callback in interface fun11', function () {
@ -124,4 +132,11 @@ describe('Test callback', function () {
let ret = testObj.fun7(onCallbackVoid);
assert.strictEqual(ret, '');
});
// function fun8(cb: (wid: boolean) => void): string;
it('test common func callback fun8', function () {
let ret = ''
ret = testObj.fun8(onCallbackBooleanVStr);
assert.strictEqual(ret, '');
});
});