Skip to content

Commit f9e48e3

Browse files
committed
test(NODE-4763): clarify hasNext test description and comments; no behavior change
1 parent 089d1bb commit f9e48e3

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

test/integration/change-streams/change_stream.test.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -396,23 +396,28 @@ describe('Change Streams', function () {
396396
}
397397
});
398398

399-
it('hasNext() does not cache the resume token', {
400-
metadata: { requires: { topology: 'replicaset' } },
401-
async test() {
402-
await initIteratorMode(changeStream);
403-
const resumeToken = changeStream.resumeToken;
399+
describe('#hasNext', () => {
400+
it('does not cache the resume token', {
401+
metadata: { requires: { topology: 'replicaset' } },
402+
async test() {
403+
await initIteratorMode(changeStream);
404+
const resumeToken = changeStream.resumeToken;
404405

405-
await collection.insertOne({ a: 1 });
406+
await collection.insertOne({ a: 1 });
406407

407-
const hasNext = await changeStream.hasNext();
408-
expect(hasNext).to.be.true;
408+
const hasNext = await changeStream.hasNext();
409+
expect(hasNext).to.be.true;
409410

410-
expect(changeStream.resumeToken).to.equal(resumeToken);
411+
// Calling .hasNext() does not allow the ChangeStream to update the token,
412+
// even when changes are present.
413+
expect(changeStream.resumeToken).to.equal(resumeToken);
411414

412-
const change = await changeStream.next();
413-
expect(change).to.have.property('_id').that.deep.equals(changeStream.resumeToken);
414-
expect(resumeToken).to.not.equal(changeStream.resumeToken);
415-
}
415+
// Consuming the change causes the ChangeStream to cache the resume token.
416+
const change = await changeStream.next();
417+
expect(change).to.have.property('_id').that.deep.equals(changeStream.resumeToken);
418+
expect(resumeToken).to.not.equal(changeStream.resumeToken);
419+
}
420+
});
416421
});
417422
});
418423

0 commit comments

Comments
 (0)