|
2 | 2 |
|
3 | 3 | const { expect } = require('chai');
|
4 | 4 | const Sinon = require('sinon');
|
| 5 | +const { Promise: BluebirdPromise } = require('bluebird'); |
5 | 6 |
|
6 | 7 | describe('Cursor Async Iterator Tests', function () {
|
7 | 8 | context('default promise library', function () {
|
@@ -87,11 +88,12 @@ describe('Cursor Async Iterator Tests', function () {
|
87 | 88 | context('custom promise library', () => {
|
88 | 89 | let client, collection, promiseSpy;
|
89 | 90 | before(async function () {
|
90 |
| - class CustomPromise extends Promise {} |
91 |
| - promiseSpy = Sinon.spy(CustomPromise.prototype, 'then'); |
92 |
| - client = this.configuration.newClient({}, { promiseLibrary: CustomPromise }); |
| 91 | + promiseSpy = Sinon.spy(BluebirdPromise.prototype, 'then'); |
| 92 | + client = this.configuration.newClient({}, { promiseLibrary: BluebirdPromise }); |
93 | 93 |
|
94 |
| - await client.connect(); |
| 94 | + const connectPromise = client.connect(); |
| 95 | + expect(connectPromise).to.be.instanceOf(BluebirdPromise); |
| 96 | + await connectPromise; |
95 | 97 | const docs = Array.from({ length: 1 }).map((_, index) => ({ foo: index, bar: 1 }));
|
96 | 98 |
|
97 | 99 | collection = client.db(this.configuration.db).collection('async_cursor_tests');
|
@@ -121,5 +123,19 @@ describe('Cursor Async Iterator Tests', function () {
|
121 | 123 | expect(countBeforeIteration).to.not.equal(promiseSpy.callCount);
|
122 | 124 | expect(promiseSpy.called).to.equal(true);
|
123 | 125 | });
|
| 126 | + |
| 127 | + it('should properly use custom promise manual iteration', async function () { |
| 128 | + const cursor = collection.find(); |
| 129 | + |
| 130 | + const iterator = cursor[Symbol.asyncIterator](); |
| 131 | + let isDone; |
| 132 | + do { |
| 133 | + const promiseFromIterator = iterator.next(); |
| 134 | + expect(promiseFromIterator).to.be.instanceOf(BluebirdPromise); |
| 135 | + const { done, value } = await promiseFromIterator; |
| 136 | + if (done) expect(value).to.be.a('undefined'); |
| 137 | + isDone = done; |
| 138 | + } while (!isDone); |
| 139 | + }); |
124 | 140 | });
|
125 | 141 | });
|
0 commit comments