()
| 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', { |
nothing calls this directly
no test coverage detected