Skip to content

Commit 04e8271

Browse files
SourceR85Steven-John Lange
andauthored
fix assert in error handler results in out of bound exception (#8861)
* assert in error handler results in out of bound exception * fix OOB in Changes with filter not present in ddoc * force CI run * force CI run * force CI run --------- Co-authored-by: Steven-John Lange <s.lange@hz-deutschland.de>
1 parent 88527c3 commit 04e8271

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

tests/integration/test.changes.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -329,17 +329,18 @@ adapters.forEach(function (adapter) {
329329
});
330330

331331
changes.on('error', (err) => {
332-
assert.equal(
333-
err.status,
334-
testUtils.errors.MISSING_DOC.status,
335-
'correct error status returned'
336-
);
337-
assert.equal(err.name, 'not_found');
338332
caughtErrors.push(err);
339333
});
340334

341335
await assert.isRejected(changes, 'completes with an exception');
342336
assert.lengthOf(caughtErrors, 1, 'changes emitted the expected error');
337+
const caughtError = caughtErrors[0];
338+
assert.equal(
339+
caughtError.status,
340+
testUtils.errors.MISSING_DOC.status,
341+
'correct error status returned'
342+
);
343+
assert.equal(caughtError.name, 'not_found');
343344
});
344345

345346
it('Changes with `filters` key not present in ddoc', async function () {
@@ -361,25 +362,26 @@ adapters.forEach(function (adapter) {
361362

362363
await testUtils.promisify(testUtils.writeDocs)(db, docs);
363364

364-
const caughtErrors = [];
365365
const changes = db.changes({
366366
filter: 'foo/even',
367367
limit: 2,
368368
include_docs: true
369369
});
370370

371-
changes.on('error', (err) => {
372-
assert.equal(
373-
err.status,
374-
testUtils.errors.MISSING_DOC.status,
375-
'correct error status returned'
376-
);
377-
assert.equal(err.name, 'not_found');
371+
const caughtErrors = [];
372+
changes.on('error', function (err) {
378373
caughtErrors.push(err);
379374
});
380375

381376
await assert.isRejected(changes, 'completes with an exception');
382-
assert.lengthOf(caughtErrors, 1, 'changes emitted the expected error');
377+
assert.equal(caughtErrors.length, 1);
378+
const caughtError = caughtErrors[0];
379+
assert.equal(
380+
caughtError.status,
381+
testUtils.errors.MISSING_DOC.status,
382+
'correct error status returned'
383+
);
384+
assert.equal(caughtError.name, 'not_found');
383385
});
384386

385387
it('Changes limit and filter', function (done) {

0 commit comments

Comments
 (0)