-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathpromise-api-tests.js
49 lines (43 loc) · 1.15 KB
/
promise-api-tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use strict'
const helper = require('./test-helper')
const pg = helper.pg
const suite = new helper.Suite()
suite.test('valid connection completes promise', () => {
const client = new pg.Client()
return client.connect()
.then(() => {
return client.end()
.then(() => { })
})
})
suite.test('valid connection completes promise', () => {
const client = new pg.Client()
return client.connect()
.then(() => {
return client.end()
.then(() => { })
})
})
suite.test('invalid connection rejects promise', (done) => {
const client = new pg.Client({ host: 'alksdjflaskdfj' })
return client.connect()
.catch(e => {
assert(e instanceof Error)
done()
})
})
suite.test('connected client does not reject promise after connection', (done) => {
const client = new pg.Client()
return client.connect()
.then(() => {
setTimeout(() => {
client.on('error', (e) => {
assert(e instanceof Error)
client.end()
done()
})
// manually kill the connection
client.emit('error', new Error('something bad happened...but not really'))
}, 50)
})
})