From 25ef6c0b2140c2c86b90ea668a40148b44d1d7d3 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Wed, 13 Jan 2021 14:32:51 -0500 Subject: [PATCH] refactor!: Clarify empty BulkOperation error message Update tests to assert TypeError is used for this API misuse NODE-2961 --- src/bulk/common.ts | 2 +- test/functional/bulk.test.js | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/bulk/common.ts b/src/bulk/common.ts index 8cb819aecfc..df015577e50 100644 --- a/src/bulk/common.ts +++ b/src/bulk/common.ts @@ -1202,7 +1202,7 @@ export abstract class BulkOperationBase { } // If we have no operations in the bulk raise an error if (this.s.batches.length === 0) { - const emptyBatchError = new TypeError('Invalid Operation, no operations specified'); + const emptyBatchError = new TypeError('Invalid BulkOperation, Batch cannot be empty'); return handleEarlyError(emptyBatchError, callback); } diff --git a/test/functional/bulk.test.js b/test/functional/bulk.test.js index 84f4a4ab868..af29799f34d 100644 --- a/test/functional/bulk.test.js +++ b/test/functional/bulk.test.js @@ -596,8 +596,8 @@ describe('Bulk', function () { var col = db.collection('batch_write_ordered_ops_8'); col.initializeOrderedBulkOp().execute(function (err) { - test.equal(err instanceof Error, true); - test.equal(err.message, 'Invalid Operation, no operations specified'); + expect(err).to.be.instanceOf(TypeError); + expect(err).to.have.property('message', 'Invalid BulkOperation, Batch cannot be empty'); client.close(done); }); @@ -1105,8 +1105,8 @@ describe('Bulk', function () { col .initializeUnorderedBulkOp() .execute(self.configuration.writeConcernMax(), function (err) { - test.equal(err instanceof Error, true); - test.equal(err.message, 'Invalid Operation, no operations specified'); + expect(err).to.be.instanceOf(TypeError); + expect(err).to.have.property('message', 'Invalid BulkOperation, Batch cannot be empty'); client.close(done); }); @@ -1516,8 +1516,9 @@ describe('Bulk', function () { client.connect(function (err, client) { var db = client.db(self.configuration.db); db.collection('doesnt_matter').insertMany([], function (err) { - test.equal(err instanceof Error, true); - test.equal(err.message, 'Invalid Operation, no operations specified'); + expect(err).to.be.instanceOf(TypeError); + expect(err).to.have.property('message', 'Invalid BulkOperation, Batch cannot be empty'); + client.close(done); }); }); @@ -1536,8 +1537,9 @@ describe('Bulk', function () { client.connect(function (err, client) { var db = client.db(self.configuration.db); db.collection('doesnt_matter').insertMany([], { ordered: false }, function (err) { - test.equal(err instanceof Error, true); - test.equal(err.message, 'Invalid Operation, no operations specified'); + expect(err).to.be.instanceOf(TypeError); + expect(err).to.have.property('message', 'Invalid BulkOperation, Batch cannot be empty'); + client.close(done); }); }); @@ -1559,8 +1561,8 @@ describe('Bulk', function () { test.equal(false, true); // this should not happen! }) .catch(function (err) { - test.equal(err instanceof Error, true); - test.equal(err.message, 'Invalid Operation, no operations specified'); + expect(err).to.be.instanceOf(TypeError); + expect(err).to.have.property('message', 'Invalid BulkOperation, Batch cannot be empty'); }) .then(function () { return client.close();