Skip to content

Commit 73b72ad

Browse files
Check if socket autoconnected
1 parent a2452ca commit 73b72ad

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

test/connection.test.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,26 @@ describe('connection', () => {
5353
const conn = new SQLiteCloudConnection(configObj)
5454
expect(conn).toBeDefined()
5555

56-
conn.connect(error => {
57-
expect(error).toBeNull()
58-
expect(conn.connected).toBe(true)
59-
56+
// already connected?
57+
if (conn.connected) {
6058
chinook.sendCommands('TEST STRING', (error, results) => {
6159
conn.close()
6260
expect(conn.connected).toBe(false)
6361
done()
6462
})
65-
})
63+
} else {
64+
// not connected, so connect...
65+
conn.connect(error => {
66+
expect(error).toBeNull()
67+
expect(conn.connected).toBe(true)
68+
69+
chinook.sendCommands('TEST STRING', (error, results) => {
70+
conn.close()
71+
expect(conn.connected).toBe(false)
72+
done()
73+
})
74+
})
75+
}
6676
})
6777

6878
it('should connect with connection string', done => {

0 commit comments

Comments
 (0)