@@ -21,30 +21,24 @@ describe("CommandQueue", () => {
2121 test ( "executes commands in FIFO order" , async ( ) => {
2222 const executionOrder : string [ ] = [ ] ;
2323
24+ function delayedResult < T > ( value : T , delayMs = 10 ) : Promise < T > {
25+ return new Promise ( ( resolve ) =>
26+ setTimeout ( ( ) => resolve ( value ) , delayMs )
27+ ) ;
28+ }
29+
2430 // Mock commands with proper Result returns
2531 const cmdA = vi . fn ( async ( ) : Promise < Result < void , unknown > > => {
26- return new Promise ( ( resolve ) => {
27- setTimeout ( ( ) => {
28- executionOrder . push ( "A" ) ;
29- resolve ( { ok : true , data : undefined } ) ;
30- } , 10 ) ;
31- } ) ;
32+ executionOrder . push ( "A" ) ;
33+ return delayedResult ( { ok : true , data : undefined } ) ;
3234 } ) ;
3335 const cmdB = vi . fn ( async ( ) : Promise < Result < void , unknown > > => {
34- return new Promise ( ( resolve ) => {
35- setTimeout ( ( ) => {
36- executionOrder . push ( "B" ) ;
37- resolve ( { ok : true , data : undefined } ) ;
38- } , 10 ) ;
39- } ) ;
36+ executionOrder . push ( "B" ) ;
37+ return delayedResult ( { ok : true , data : undefined } ) ;
4038 } ) ;
4139 const cmdC = vi . fn ( async ( ) : Promise < Result < void , unknown > > => {
42- return new Promise ( ( resolve ) => {
43- setTimeout ( ( ) => {
44- executionOrder . push ( "C" ) ;
45- resolve ( { ok : true , data : undefined } ) ;
46- } , 10 ) ;
47- } ) ;
40+ executionOrder . push ( "C" ) ;
41+ return delayedResult ( { ok : true , data : undefined } ) ;
4842 } ) ;
4943
5044 // We'll assume checkSetup always ok for this test
@@ -107,12 +101,14 @@ describe("CommandQueue", () => {
107101
108102 test ( "logs errors if a command throws or returns error" , async ( ) => {
109103 // Spy on console.error to see if it's called
110- const consoleErrorSpy = vi . spyOn ( console , "error" ) . mockImplementation ( ( ) => {
111- return {
112- ok : true ,
113- data : undefined ,
114- } ;
115- } ) ;
104+ const consoleErrorSpy = vi
105+ . spyOn ( console , "error" )
106+ . mockImplementation ( ( ) => {
107+ return {
108+ ok : true ,
109+ data : undefined ,
110+ } ;
111+ } ) ;
116112
117113 // Force checkSetup to succeed
118114 vi . mocked ( checkSetup ) . mockReturnValue ( { ok : true , data : undefined } ) ;
@@ -131,7 +127,10 @@ describe("CommandQueue", () => {
131127 queue . add ( failingCmd , true ) ;
132128 await queue . wait ( ) ;
133129
134- expect ( consoleErrorSpy ) . toHaveBeenCalledWith ( "🧱 Formbricks - Global error: " , expect . any ( Error ) ) ;
130+ expect ( consoleErrorSpy ) . toHaveBeenCalledWith (
131+ "🧱 Formbricks - Global error: " ,
132+ expect . any ( Error )
133+ ) ;
135134 consoleErrorSpy . mockRestore ( ) ;
136135 } ) ;
137136
0 commit comments