diff --git a/test/docs/transactions.test.js b/test/docs/transactions.test.js index e21639331b9..f40067a71ea 100644 --- a/test/docs/transactions.test.js +++ b/test/docs/transactions.test.js @@ -479,7 +479,7 @@ describe('transactions', function() { const doc = await Test.findById(_id).orFail(); let attempt = 0; - await db.transaction(async(session) => { + const res = await db.transaction(async(session) => { await doc.save({ session }); if (attempt === 0) { @@ -489,7 +489,10 @@ describe('transactions', function() { errorLabels: [mongoose.mongo.MongoErrorLabel.TransientTransactionError] }); } + + return { answer: 42 }; }); + assert.deepStrictEqual(res, { answer: 42 }); const { items } = await Test.findById(_id).orFail(); assert.ok(Array.isArray(items)); diff --git a/test/types/connection.test.ts b/test/types/connection.test.ts index c5979663a20..db721ebbb21 100644 --- a/test/types/connection.test.ts +++ b/test/types/connection.test.ts @@ -45,11 +45,11 @@ expectType(conn.db); expectType(conn.getClient()); expectType(conn.setClient(new mongodb.MongoClient('mongodb://127.0.0.1:27017/test'))); -expectType>(conn.transaction(async(res) => { +expectType>(conn.transaction(async(res) => { expectType(res); return 'a'; })); -expectType>(conn.transaction(async(res) => { +expectType>(conn.transaction(async(res) => { expectType(res); return 'a'; }, { readConcern: 'majority' })); @@ -148,4 +148,4 @@ function schemaInstanceMethodsAndQueryHelpersOnConnection() { }); const TestModel = connection.model('User', userSchema); -} +} \ No newline at end of file diff --git a/types/connection.d.ts b/types/connection.d.ts index 2f47bdc84e5..879e4d98e06 100644 --- a/types/connection.d.ts +++ b/types/connection.d.ts @@ -236,7 +236,7 @@ declare module 'mongoose' { * async function executes successfully and attempt to retry if * there was a retryable error. */ - transaction(fn: (session: mongodb.ClientSession) => Promise, options?: mongodb.TransactionOptions): Promise; + transaction(fn: (session: mongodb.ClientSession) => Promise, options?: mongodb.TransactionOptions): Promise; /** Switches to a different database using the same connection pool. */ useDb(name: string, options?: { useCache?: boolean, noListener?: boolean }): Connection;