Add test for connection failure rejecting properly

This commit is contained in:
Brian Carlson 2025-07-19 06:43:41 -05:00
parent 0328cb30ae
commit c489cfee71

View File

@ -147,4 +147,22 @@ describe('Transaction', () => {
assert.equal(rows.length, 1, 'Row should be visible after transaction with return value')
pool.end()
})
it('does not throw an uncatchable error if pool cannot connect', async () => {
const pool = new Pool({
connectionString: 'postgres://invalid:invalid@localhost:5432/invalid_db',
})
const promise = transaction(pool, async (client) => {
await client.query('SELECT 1')
})
try {
await assert.rejects(promise, {
name: 'error',
})
} finally {
await pool.end()
}
})
})