@@ -384,6 +384,64 @@ test("async function can forward varargs", () => {
384384 . expectToEqual ( [ "resolved" , "A" , "B" , "C" ] ) ;
385385} ) ;
386386
387+ test . each ( [ "async function abc() {" , "const abc = async () => {" ] ) (
388+ "can throw error after await in async function (%p)" ,
389+ functionHeader => {
390+ util . testFunction `
391+ const { promise, resolve } = defer<string>();
392+ promise.then(data => log("resolving first promise", data));
393+
394+ ${ functionHeader }
395+ await promise;
396+ log("run abc");
397+ throw "test throw";
398+ }
399+
400+ const awaitingPromise = abc();
401+ awaitingPromise.catch(error => log("caught error", error));
402+
403+ resolve("resolved data");
404+ return allLogs;
405+ `
406+ . setTsHeader ( promiseTestLib )
407+ . expectToEqual ( [ "resolving first promise" , "resolved data" , "run abc" , "caught error" , "test throw" ] ) ;
408+ }
409+ ) ;
410+
411+ test . each ( [ "async function abc() {" , "const abc = async () => {" ] ) (
412+ "can throw object after await in async function (%p)" ,
413+ functionHeader => {
414+ util . testFunction `
415+ const { promise, resolve } = defer<string>();
416+ promise.then(data => log("resolving first promise", data));
417+
418+ ${ functionHeader }
419+ await promise;
420+ log("run abc");
421+ throw new Error("test throw");
422+ }
423+
424+ const awaitingPromise = abc();
425+ awaitingPromise.catch(error => log("caught error", error));
426+
427+ resolve("resolved data");
428+ return allLogs;
429+ `
430+ . setTsHeader ( promiseTestLib )
431+ . expectToEqual ( [
432+ "resolving first promise" ,
433+ "resolved data" ,
434+ "run abc" ,
435+ "caught error" ,
436+ {
437+ message : "test throw" ,
438+ name : "Error" ,
439+ stack : expect . stringContaining ( "stack traceback" ) ,
440+ } ,
441+ ] ) ;
442+ }
443+ ) ;
444+
387445// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1105
388446describe ( "try/catch in async function" , ( ) => {
389447 util . testEachVersion (
0 commit comments