MCPcopy
hub / github.com/mongodb/node-mongodb-native / test

Function test

test/integration/crud/crud.prose.test.ts:105–126  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

103 it('test case: insert MongoServerError', {
104 metadata: { requires: { mongodb: '>=5.0.0' } },
105 async test() {
106 const evCapture = once(client, 'commandSucceeded');
107
108 let errInfoFromError;
109 try {
110 await collection.insertOne({ x: /not a string/ });
111 expect.fail('The insert should fail the validation that x must be a string');
112 } catch (error) {
113 expect(error).to.be.instanceOf(MongoServerError);
114 expect(error).to.have.property('code', 121);
115 expect(error).to.have.property('errInfo').that.is.an('object');
116 errInfoFromError = error.errInfo;
117 }
118
119 const commandSucceededEvents = await evCapture;
120 expect(commandSucceededEvents).to.have.lengthOf(1);
121 const ev = commandSucceededEvents[0];
122 expect(ev).to.have.nested.property('reply.writeErrors[0].errInfo').that.is.an('object');
123
124 const errInfoFromEvent = ev.reply.writeErrors[0].errInfo;
125 expect(errInfoFromError).to.deep.equal(errInfoFromEvent);
126 }
127 });
128
129 it('test case: insertMany MongoBulkWriteError', {

Callers

nothing calls this directly

Calls 8

onceFunction · 0.85
insertOneMethod · 0.80
failMethod · 0.80
insertManyMethod · 0.80
countDocumentsMethod · 0.80
collectionMethod · 0.65
bulkWriteMethod · 0.45
dbMethod · 0.45

Tested by

no test coverage detected