@@ -19,7 +19,10 @@ const suite = new helper.Suite('error handling')
19
19
20
20
suite . test ( 'sending non-array argument as values causes an error callback' , ( done ) => {
21
21
const client = new Client ( )
22
- client . connect ( ( ) => {
22
+ client . connect ( ( err ) => {
23
+ if ( err ) {
24
+ return done ( err )
25
+ }
23
26
client . query ( 'select $1::text as name' , 'foo' , ( err ) => {
24
27
assert ( err instanceof Error )
25
28
client . query ( 'SELECT $1::text as name' , [ 'foo' ] , ( err , res ) => {
@@ -32,27 +35,33 @@ suite.test('sending non-array argument as values causes an error callback', (don
32
35
33
36
suite . test ( 're-using connections results in error callback' , ( done ) => {
34
37
const client = new Client ( )
35
- client . connect ( ( ) => {
38
+ client . connect ( ( err ) => {
39
+ if ( err ) {
40
+ return done ( err )
41
+ }
36
42
client . connect ( ( err ) => {
37
43
assert ( err instanceof Error )
38
44
client . end ( done )
39
45
} )
40
46
} )
41
47
} )
42
48
43
- suite . test ( 're-using connections results in promise rejection' , ( done ) => {
49
+ suite . testAsync ( 're-using connections results in promise rejection' , ( ) => {
44
50
const client = new Client ( )
45
- client . connect ( ) . then ( ( ) => {
46
- client . connect ( ) . catch ( ( err ) => {
51
+ return client . connect ( ) . then ( ( ) => {
52
+ return helper . rejection ( client . connect ( ) ) . then ( ( err ) => {
47
53
assert ( err instanceof Error )
48
- client . end ( ) . then ( done )
54
+ return client . end ( )
49
55
} )
50
56
} )
51
57
} )
52
58
53
59
suite . test ( 'using a client after closing it results in error' , ( done ) => {
54
60
const client = new Client ( )
55
- client . connect ( ( ) => {
61
+ client . connect ( ( err ) => {
62
+ if ( err ) {
63
+ return done ( err )
64
+ }
56
65
client . end (
57
66
assert . calls ( ( ) => {
58
67
client . query (
@@ -227,12 +236,16 @@ suite.test('connected, idle client error', (done) => {
227
236
228
237
suite . test ( 'cannot pass non-string values to query as text' , ( done ) => {
229
238
const client = new Client ( )
230
- client . connect ( )
231
- client . query ( { text : { } } , ( err ) => {
232
- assert ( err )
233
- client . query ( { } , ( err ) => {
234
- client . on ( 'drain' , ( ) => {
235
- client . end ( done )
239
+ client . connect ( ( err ) => {
240
+ if ( err ) {
241
+ return done ( err )
242
+ }
243
+ client . query ( { text : { } } , ( err ) => {
244
+ assert ( err )
245
+ client . query ( { } , ( err ) => {
246
+ client . on ( 'drain' , ( ) => {
247
+ client . end ( done )
248
+ } )
236
249
} )
237
250
} )
238
251
} )
0 commit comments