@@ -52,7 +52,7 @@ describe("Terminal", () => {
5252 vi . clearAllMocks ( )
5353 } )
5454
55- it ( "should prepend cd command if requestedCwd differs from currentCwd" , ( ) => {
55+ it ( "should prepend cd command if requestedCwd differs from currentCwd" , async ( ) => {
5656 terminal . requestedCwd = "/requested/cwd"
5757 vi . spyOn ( terminal , "getCurrentWorkingDirectory" ) . mockReturnValue ( "/initial/cwd" )
5858
@@ -65,11 +65,14 @@ describe("Terminal", () => {
6565
6666 terminal . runCommand ( "ls" , callbacks )
6767
68- expect ( mockProcess . command ) . toBe ( 'cd "/requested/cwd" && ls' )
69- expect ( mockRun ) . toHaveBeenCalledWith ( 'cd "/requested/cwd" && ls' )
68+ // Wait for the async operation to complete
69+ await vi . waitFor ( ( ) => {
70+ expect ( mockProcess . command ) . toBe ( 'cd "/requested/cwd" && ls' )
71+ expect ( mockRun ) . toHaveBeenCalledWith ( 'cd "/requested/cwd" && ls' )
72+ } )
7073 } )
7174
72- it ( "should not prepend cd command if requestedCwd is the same as currentCwd" , ( ) => {
75+ it ( "should not prepend cd command if requestedCwd is the same as currentCwd" , async ( ) => {
7376 terminal . requestedCwd = "/initial/cwd"
7477 vi . spyOn ( terminal , "getCurrentWorkingDirectory" ) . mockReturnValue ( "/initial/cwd" )
7578 const callbacks = {
@@ -81,11 +84,14 @@ describe("Terminal", () => {
8184
8285 terminal . runCommand ( "ls" , callbacks )
8386
84- expect ( mockProcess . command ) . toBe ( "ls" )
85- expect ( mockRun ) . toHaveBeenCalledWith ( "ls" )
87+ // Wait for the async operation to complete
88+ await vi . waitFor ( ( ) => {
89+ expect ( mockProcess . command ) . toBe ( "ls" )
90+ expect ( mockRun ) . toHaveBeenCalledWith ( "ls" )
91+ } )
8692 } )
8793
88- it ( "should not prepend cd command if requestedCwd is not set" , ( ) => {
94+ it ( "should not prepend cd command if requestedCwd is not set" , async ( ) => {
8995 vi . spyOn ( terminal , "getCurrentWorkingDirectory" ) . mockReturnValue ( "/initial/cwd" )
9096 const callbacks = {
9197 onLine : vi . fn ( ) ,
@@ -96,8 +102,11 @@ describe("Terminal", () => {
96102
97103 terminal . runCommand ( "ls" , callbacks )
98104
99- expect ( mockProcess . command ) . toBe ( "ls" )
100- expect ( mockRun ) . toHaveBeenCalledWith ( "ls" )
105+ // Wait for the async operation to complete
106+ await vi . waitFor ( ( ) => {
107+ expect ( mockProcess . command ) . toBe ( "ls" )
108+ expect ( mockRun ) . toHaveBeenCalledWith ( "ls" )
109+ } )
101110 } )
102111 } )
103- } )
112+ } )
0 commit comments