Skip to content

Commit cbdb6ba

Browse files
committed
add test for PR 2862
1 parent d3749de commit cbdb6ba

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict'
2+
var helper = require('./../test-helper')
3+
var assert = require('assert')
4+
var util = require('util')
5+
var vm = require('node:vm');
6+
7+
const suite = new helper.Suite()
8+
9+
suite.test('Handle date objects as Date', async (done) => {
10+
const date = new Date();
11+
const dateObj = await vm.runInNewContext('new Date()');
12+
assert(!(dateObj instanceof Date))
13+
assert(util.types.isDate(dateObj))
14+
const client = new helper.pg.Client()
15+
client.connect()
16+
17+
await client.query('CREATE TEMP TABLE foo(bar TIMESTAMP, bar2 TIMESTAMP)')
18+
await client.query('INSERT INTO foo(bar, bar2) VALUES($1, $2)', [date, dateObj])
19+
const results = await client.query('SELECT * FROM foo')
20+
const row = results.rows[0]
21+
const dbDate = row.bar
22+
const dbDateObj = row.bar2
23+
assert.deepEqual(dbDate, date)
24+
assert.deepEqual(dbDateObj, dateObj)
25+
await client.end()
26+
done()
27+
})

0 commit comments

Comments
 (0)