-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathexample-commonjs-test.js
More file actions
45 lines (37 loc) · 1.21 KB
/
Copy pathexample-commonjs-test.js
File metadata and controls
45 lines (37 loc) · 1.21 KB
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
'use strict'
// CommonJS-style test file that works with chai-as-promised v7
const chai = require('chai')
const chaiAsPromised = require('chai-as-promised')
const { TestEnv } = require('./env/test-env')
// Setup chai
chai.use(chaiAsPromised)
const { expect } = chai
describe('Example CommonJS Test', function () {
this.timeout(30000)
let env
before(async function () {
env = new TestEnv()
await env.open()
})
after(async function () {
if (env) {
await env.close()
}
})
it('should handle promises correctly', async function () {
// Test promise resolution
const result = await env.theConnection.promises.query('SELECT 1 as num')
expect(result.first[0].num).to.equal(1)
})
it('should handle promise rejection', async function () {
// Test promise rejection with chai-as-promised
const badQuery = env.theConnection.promises.query('SELECT * FROM NonExistentTable')
await expect(badQuery).to.be.rejected
})
it('should test with eventually', function () {
// Using eventually for async assertions
const promise = env.theConnection.promises.query('SELECT 42 as answer')
return expect(promise).to.eventually.have.property('first')
.that.has.length(1)
})
})