1
+ import { setTimeout } from 'node:timers/promises' ;
1
2
import type { LambdaInterface } from '@aws-lambda-powertools/commons/types' ;
2
3
import context from '@aws-lambda-powertools/testing-utils/context' ;
3
4
import type { Context } from 'aws-lambda' ;
@@ -7,15 +8,16 @@ import { BasePersistenceLayer } from '../../src/persistence/BasePersistenceLayer
7
8
import { PersistenceLayerTestClass } from '../helpers/idempotencyUtils.js' ;
8
9
9
10
describe ( 'Given a class with a function to decorate' , ( ) => {
10
- it ( 'maintains the scope of the decorated function' , ( ) => {
11
+ it ( 'maintains the scope of the decorated function' , async ( ) => {
11
12
// Prepare
12
13
class TestClass implements LambdaInterface {
13
14
private readonly foo = 'foo' ;
14
15
15
16
@idempotent ( {
16
17
persistenceStore : new PersistenceLayerTestClass ( ) ,
17
18
} )
18
- public handler ( _event : unknown , _context : Context ) {
19
+ public async handler ( _event : unknown , _context : Context ) {
20
+ await setTimeout ( 0 ) ; // Simulate some async operation
19
21
return this . privateMethod ( ) ;
20
22
}
21
23
@@ -28,7 +30,7 @@ describe('Given a class with a function to decorate', () => {
28
30
const handler = handlerClass . handler . bind ( handlerClass ) ;
29
31
30
32
// Act
31
- const result = handler ( { } , context ) ;
33
+ const result = await handler ( { } , context ) ;
32
34
33
35
// Assess
34
36
expect ( result ) . toBe ( 'private foo' ) ;
0 commit comments