|
| 1 | +import { expect } from 'chai'; |
| 2 | +import * as sinon from 'sinon'; |
| 3 | + |
| 4 | +import { type MongoClient } from '../../../src'; |
| 5 | + |
| 6 | +describe('Symbol.asyncDispose implementation tests', function () { |
| 7 | + let client: MongoClient; |
| 8 | + |
| 9 | + afterEach(async function () { |
| 10 | + await client?.close(); |
| 11 | + }); |
| 12 | + |
| 13 | + describe('Symbol.asyncDispose defined', function () { |
| 14 | + describe('MongoClient', function () { |
| 15 | + it('the Symbol.asyncDispose method calls close()', async function () { |
| 16 | + client = this.configuration.newClient(); |
| 17 | + |
| 18 | + const spy = sinon.spy(client, 'close'); |
| 19 | + await client[Symbol.asyncDispose](); |
| 20 | + expect(spy.called).to.be.true; |
| 21 | + }); |
| 22 | + }); |
| 23 | + |
| 24 | + describe('ClientSession', function () { |
| 25 | + it('the Symbol.asyncDispose method calls endSession()', async function () { |
| 26 | + client = this.configuration.newClient(); |
| 27 | + const session = client.startSession(); |
| 28 | + |
| 29 | + const spy = sinon.spy(session, 'endSession'); |
| 30 | + await session[Symbol.asyncDispose](); |
| 31 | + expect(spy.called).to.be.true; |
| 32 | + }); |
| 33 | + }); |
| 34 | + |
| 35 | + describe('ChangeStreams', function () { |
| 36 | + it('the Symbol.asyncDispose method calls close()', async function () { |
| 37 | + client = this.configuration.newClient(); |
| 38 | + const changeStream = client.watch(); |
| 39 | + |
| 40 | + const spy = sinon.spy(changeStream, 'close'); |
| 41 | + await changeStream[Symbol.asyncDispose](); |
| 42 | + expect(spy.called).to.be.true; |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | + describe('cursors', function () { |
| 47 | + it('the Symbol.asyncDispose method calls close()', async function () { |
| 48 | + client = this.configuration.newClient(); |
| 49 | + const cursor = client.db('foo').collection('bar').find(); |
| 50 | + |
| 51 | + const spy = sinon.spy(cursor, 'close'); |
| 52 | + await cursor[Symbol.asyncDispose](); |
| 53 | + expect(spy.called).to.be.true; |
| 54 | + }); |
| 55 | + }); |
| 56 | + }); |
| 57 | +}); |
0 commit comments