@@ -105,7 +105,6 @@ describe('dbConnect', () => {
105105 process . env . MONGODB_URI = 'mongodb://localhost:27017/test' ;
106106 global . mongoose . conn = null ;
107107
108- //const mockMongoose = { connection: 'mock' };
109108 vi . mocked ( mongoose . connect ) . mockRejectedValue ( new Error ( 'Database is disconnected' ) ) ;
110109
111110 await expect ( dbConnect ( ) ) . rejects . toThrow ( 'Database is disconnected' ) ;
@@ -114,21 +113,6 @@ describe('dbConnect', () => {
114113 expect ( global . mongoose . promise ) . toBeNull ( ) ;
115114 } ) ;
116115
117- it ( 'handles mongoose Connection State 3 (disconnecting) gracefully' , async ( ) => {
118- process . env . MONGODB_URI = 'mongodb://localhost:27017/test' ;
119- global . mongoose . conn = null ;
120- mockMongooseConnection . readyState = 3 ;
121-
122- const mockMongoose = { connection : 'mock' } ;
123- setConnectedMongoose ( mockMongoose as unknown as typeof mongoose ) ;
124-
125- const conn = await dbConnect ( ) ;
126-
127- expect ( mongoose . connect ) . toHaveBeenCalledTimes ( 1 ) ;
128- expect ( conn ) . toBe ( mockMongoose ) ;
129- expect ( global . mongoose . conn ) . toBe ( mockMongoose ) ;
130- } ) ;
131-
132116 it ( 'returns the cached connection immediately when mongoose is already connected' , async ( ) => {
133117 process . env . MONGODB_URI = 'mongodb://localhost:27017/test' ;
134118
@@ -169,13 +153,17 @@ describe('dbConnect', () => {
169153
170154 it ( 'handles mongoose Connection State 3 (disconnecting) gracefully' , async ( ) => {
171155 process . env . MONGODB_URI = 'mongodb://localhost:27017/test' ;
156+ global . mongoose . conn = null ;
172157 mockMongooseConnection . readyState = 3 ;
173- const mockMDB = { connection : 'mock' } ;
174- setConnectedMongoose ( mockMDB as unknown as typeof mongoose ) ;
175158
176- const res = await dbConnect ( ) ;
159+ const mockMongoose = { connection : 'mock' } ;
160+ setConnectedMongoose ( mockMongoose as unknown as typeof mongoose ) ;
161+
162+ const conn = await dbConnect ( ) ;
163+
177164 expect ( mongoose . connect ) . toHaveBeenCalledTimes ( 1 ) ;
178- expect ( res ) . toBe ( mockMDB ) ;
165+ expect ( conn ) . toBe ( mockMongoose ) ;
166+ expect ( global . mongoose . conn ) . toBe ( mockMongoose ) ;
179167 } ) ;
180168
181169 it ( 'reuses an in-flight promise when state 3 triggers concurrent dbConnect calls' , async ( ) => {
0 commit comments