@@ -5,7 +5,10 @@ import type { HawkJavaScriptEvent } from '../src/types/event';
55import Catcher from '../src/catcher' ;
66
77const TEST_TOKEN = 'eyJpbnRlZ3JhdGlvbklkIjoiOTU3MmQyOWQtNWJhZS00YmYyLTkwN2MtZDk5ZDg5MGIwOTVmIiwic2VjcmV0IjoiZTExODFiZWItMjdlMS00ZDViLWEwZmEtZmUwYTM1Mzg5OWMyIn0=' ;
8- const flush = ( ) : Promise < void > => new Promise ( ( r ) => setTimeout ( r , 0 ) ) ;
8+ /**
9+ * Wait for fire-and-forget async calls inside hawk.send() to complete
10+ */
11+ const wait = ( ) : Promise < void > => new Promise ( ( r ) => setTimeout ( r , 0 ) ) ;
912
1013function createTransport ( ) {
1114 const sendSpy = vi . fn < ( msg : CatcherMessage ) => Promise < void > > ( ) . mockResolvedValue ( undefined ) ;
@@ -51,7 +54,7 @@ describe('beforeSend', () => {
5154
5255 // Act
5356 hawk . send ( new Error ( 'hello' ) ) ;
54- await flush ( ) ;
57+ await wait ( ) ;
5558
5659 // Assert
5760 expect ( sendSpy ) . toHaveBeenCalledOnce ( ) ;
@@ -69,7 +72,7 @@ describe('beforeSend', () => {
6972
7073 // Act
7174 hawk . send ( new Error ( 'modify' ) ) ;
72- await flush ( ) ;
75+ await wait ( ) ;
7376
7477 // Assert
7578 expect ( sendSpy ) . toHaveBeenCalledOnce ( ) ;
@@ -83,7 +86,7 @@ describe('beforeSend', () => {
8386
8487 // Act
8588 hawk . send ( new Error ( 'drop' ) ) ;
86- await flush ( ) ;
89+ await wait ( ) ;
8790
8891 // Assert
8992 expect ( sendSpy ) . not . toHaveBeenCalled ( ) ;
@@ -103,7 +106,7 @@ describe('beforeSend', () => {
103106
104107 // Act
105108 hawk . send ( new Error ( 'invalid' ) ) ;
106- await flush ( ) ;
109+ await wait ( ) ;
107110
108111 // Assert
109112 expect ( sendSpy ) . toHaveBeenCalledOnce ( ) ;
@@ -127,7 +130,7 @@ describe('beforeSend', () => {
127130
128131 // Act
129132 hawk . send ( new Error ( 'required-field' ) ) ;
130- await flush ( ) ;
133+ await wait ( ) ;
131134
132135 // Assert — fallback to original payload, title preserved
133136 expect ( sendSpy ) . toHaveBeenCalledOnce ( ) ;
@@ -150,7 +153,7 @@ describe('beforeSend', () => {
150153
151154 // Act
152155 hawk . send ( new Error ( 'optional' ) ) ;
153- await flush ( ) ;
156+ await wait ( ) ;
154157
155158 // Assert
156159 expect ( sendSpy ) . toHaveBeenCalledOnce ( ) ;
0 commit comments