Skip to content

Commit 02cbb51

Browse files
committed
chore: comments
1 parent 270da11 commit 02cbb51

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/mongo_client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export type SupportedSocketOptions = Pick<
118118
TcpNetConnectOpts & {
119119
autoSelectFamily?: boolean;
120120
autoSelectFamilyAttemptTimeout?: number;
121-
/** Node.JS socket option to set the time the first keepalive probe is sent on an idle socket. */
121+
/** Node.JS socket option to set the time the first keepalive probe is sent on an idle socket. Defaults to 120000ms */
122122
keepAliveInitialDelay?: number;
123123
},
124124
(typeof LEGAL_TCP_SOCKET_OPTIONS)[number]

test/integration/node-specific/mongo_client.test.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ describe('class MongoClient', function () {
214214
spy.restore();
215215
});
216216

217-
it('sets the option to 0', {
217+
it('the Node.js runtime sets the option to 0', {
218218
metadata: { requires: { apiVersion: false } },
219219
test: function () {
220220
expect(spy).to.have.been.calledWith(
@@ -226,6 +226,34 @@ describe('class MongoClient', function () {
226226
}
227227
});
228228
});
229+
230+
context('when the value is mistyped', function () {
231+
// Set server selection timeout to get the error quicker.
232+
const options = { keepAliveInitialDelay: 'test', serverSelectionTimeoutMS: 1000 };
233+
let client;
234+
let spy;
235+
236+
beforeEach(async function () {
237+
spy = sinon.spy(net, 'createConnection');
238+
const uri = this.configuration.url();
239+
client = new MongoClient(uri, options);
240+
});
241+
242+
afterEach(async function () {
243+
await client?.close();
244+
spy.restore();
245+
});
246+
247+
it('throws an error', {
248+
metadata: { requires: { apiVersion: false } },
249+
test: async function () {
250+
const error = await client.connect().catch(error => error);
251+
expect(error.message).to.include(
252+
'property must be of type number. Received type string'
253+
);
254+
}
255+
});
256+
});
229257
});
230258

231259
context('when keepAliveInitialDelay is not provided', function () {

0 commit comments

Comments
 (0)