Skip to content

Commit c489cfe

Browse files
committed
Add test for connection failure rejecting properly
1 parent 0328cb3 commit c489cfe

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

packages/pg-transaction/src/index.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,22 @@ describe('Transaction', () => {
147147
assert.equal(rows.length, 1, 'Row should be visible after transaction with return value')
148148
pool.end()
149149
})
150+
151+
it('does not throw an uncatchable error if pool cannot connect', async () => {
152+
const pool = new Pool({
153+
connectionString: 'postgres://invalid:invalid@localhost:5432/invalid_db',
154+
})
155+
156+
const promise = transaction(pool, async (client) => {
157+
await client.query('SELECT 1')
158+
})
159+
160+
try {
161+
await assert.rejects(promise, {
162+
name: 'error',
163+
})
164+
} finally {
165+
await pool.end()
166+
}
167+
})
150168
})

0 commit comments

Comments
 (0)