@@ -7,11 +7,33 @@ import {
77import { Do , DoSync } from "../utilities/do-try" ;
88import { PolyfillUtils } from "../utilities/polyfill-utils" ;
99import { StubResourceRecord } from "../tests/stubs/stub-resource-record" ;
10+ import { CoreUtils } from "../utilities/core-utils" ;
1011
1112PolyfillUtils . registerPromiseFinallyPolyfill ( ) ;
1213
1314describe ( "do-try.ts" , ( ) => {
1415 describe ( "Do.try" , ( ) => {
16+ it ( "When a catch handler exists, finally is called after catch resolves" , async ( ) => {
17+ // Arrange
18+ let catchRanAtTimestamp : number ;
19+ let finallyRanAtTimestamp : number ;
20+ const workload = async ( ) => {
21+ throw Error ( ) ;
22+ } ;
23+
24+ // Act
25+ await Do . try ( workload )
26+ . catch ( ( ) => {
27+ catchRanAtTimestamp = Date . now ( ) ;
28+ CoreUtils . sleepSync ( 1000 ) ;
29+ } )
30+ . finally ( ( ) => ( finallyRanAtTimestamp = Date . now ( ) ) )
31+ . getAwaiter ( ) ;
32+
33+ // Assert
34+ expect ( catchRanAtTimestamp ) . toBeLessThan ( finallyRanAtTimestamp ) ;
35+ } ) ;
36+
1537 it ( "When validation errors occur (i.e. error is a ResultRecord), then passes typed errors to catch handler" , async ( ) => {
1638 // Arrange
1739 const workload = async ( ) => {
@@ -54,7 +76,7 @@ describe("do-try.ts", () => {
5476 it ( "When no errors occur, then catch handler is never called" , async ( ) => {
5577 // Arrange
5678 const catchHandler = jest . fn ( ) ;
57- const workload = jest . fn ( ) ;
79+ const workload = async ( ) => { } ;
5880
5981 // Act
6082 await Do . try ( workload )
@@ -68,7 +90,7 @@ describe("do-try.ts", () => {
6890 it ( "When no errors occur, then finally handler is still called" , async ( ) => {
6991 // Arrange
7092 const finallyHandler = jest . fn ( ) ;
71- const workload = jest . fn ( ) ;
93+ const workload = async ( ) => { } ;
7294
7395 // Act
7496 await Do . try ( workload )
0 commit comments