Skip to content

Commit 9835b6d

Browse files
committed
test: ensure findOne calls cursor.close
1 parent c51d47e commit 9835b6d

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

test/integration/crud/crud_api.test.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { expect } from 'chai';
22
import { on } from 'events';
3-
4-
import { type MongoClient, MongoError, ObjectId, ReturnDocument } from '../../mongodb';
3+
import * as sinon from 'sinon';
4+
5+
import {
6+
AbstractCursor,
7+
type MongoClient,
8+
MongoError,
9+
ObjectId,
10+
ReturnDocument
11+
} from '../../mongodb';
512
import { assert as test } from '../shared';
613

714
// instanceof cannot be use reliably to detect the new models in js due to scoping and new
@@ -31,6 +38,8 @@ describe('CRUD API', function () {
3138
});
3239

3340
afterEach(async function () {
41+
sinon.restore();
42+
3443
await client?.close();
3544
client = null;
3645

@@ -61,6 +70,12 @@ describe('CRUD API', function () {
6170
await client.close();
6271
});
6372

73+
it('findOne calls cursor.close()', async function () {
74+
const spy = sinon.spy(AbstractCursor.prototype, 'close');
75+
await client.db().collection('t').findOne({});
76+
expect(spy).to.be.calledOnce;
77+
});
78+
6479
context('when creating a cursor with find', () => {
6580
let collection;
6681

0 commit comments

Comments
 (0)