test: Add test coverage for logical termination#1743
Conversation
f91e1a5 to
bb2015d
Compare
bb2015d to
da544d4
Compare
da544d4 to
5bf5e0b
Compare
5bf5e0b to
885ecec
Compare
2897101 to
2d168b0
Compare
c3d8246 to
bd095b1
Compare
MarkDuckworth
left a comment
There was a problem hiding this comment.
The new tests look fine, but the use of promises could be improved for readability and consistency. I gave a few suggestions for improvement.
|
|
||
| it('can stream()', done => { | ||
| let received = 0; | ||
| return randomCol |
There was a problem hiding this comment.
You shouldn't need to return the result here. Returning anything could be misleading, since it could be confused with returning a promise, and I think this code is returning a Stream.
You use the done callback to signal that the test is complete instead of returning a promise. That's fine since that pattern is used in other tests in this file.
|
|
||
| it('has limit() method on stream()', done => { | ||
| let received = 0; | ||
| Promise.all([addDocs({foo: 'a'}, {foo: 'b'})]).then(() => { |
There was a problem hiding this comment.
Wrapping this statement in Promise.all(...) is misleading, and I don't think it adds value. Consider instead
addDocs(...).then(...
|
|
||
| it('can run limit(num), where num is larger than the collection size on stream()', done => { | ||
| let received = 0; | ||
| Promise.all([addDocs({foo: 'a'}, {foo: 'b'})]).then(() => { |
| }); | ||
|
|
||
| it('has offset() method', async () => { | ||
| it('has offset() method on get()', async () => { |
There was a problem hiding this comment.
Offset method is on Query. Maybe consider rewording this test to 'can use offset() method with get()'
| expectDocs(res, {foo: 'b'}); | ||
| }); | ||
|
|
||
| it('has offset() method on stream()', done => { |
There was a problem hiding this comment.
Offset method is on Query. Maybe consider rewording this test to 'can use offset() method with get()'
|
|
||
| it('has offset() method on stream()', done => { | ||
| let received = 0; | ||
| Promise.all([addDocs({foo: 'a'}, {foo: 'b'})]).then(() => { |
There was a problem hiding this comment.
Same concern with use of Promise.all
|
|
||
| it('can run offset(num), where num is larger than the collection size on stream()', done => { | ||
| let received = 0; | ||
| Promise.all([addDocs({foo: 'a'}, {foo: 'b'})]).then(() => { |
There was a problem hiding this comment.
Same concern with use of Promise.all
7b1d052 to
6307c44
Compare
8c1ae2f to
c02f2c5
Compare
MarkDuckworth
left a comment
There was a problem hiding this comment.
Approve with additional recommendations on clean up.
| for await (const doc of stream) { | ||
| expect(doc).to.be.an.instanceOf(QueryDocumentSnapshot); | ||
| ++received; | ||
| } |
There was a problem hiding this comment.
Nice use of for await...of!
| await addDocs({foo: 'a'}, {foo: 'b'}).then(async () => { | ||
| const stream = randomCol.orderBy('foo').limit(1).stream(); | ||
| for await (const doc of stream) { | ||
| expect(doc).to.be.an.instanceOf(QueryDocumentSnapshot); | ||
| ++received; | ||
| } | ||
|
|
||
| expect(received).to.equal(1); | ||
| }); |
There was a problem hiding this comment.
Nit: since you have an async test, you can drop the use of promise.then(...) and make the code even more readable.
await addDocs({foo: 'a'}, {foo: 'b'});
const stream = randomCol.orderBy('foo').limit(1).stream();
for await (const doc of stream) {
expect(doc).to.be.an.instanceOf(QueryDocumentSnapshot);
++received;
}
expect(received).to.equal(1);
| await addDocs({foo: 'a'}, {foo: 'b'}).then(async () => { | ||
| const stream = randomCol.orderBy('foo').limit(3).stream(); | ||
| for await (const doc of stream) { | ||
| expect(doc).to.be.an.instanceOf(QueryDocumentSnapshot); | ||
| ++received; | ||
| } | ||
| expect(received).to.equal(2); | ||
| }); |
| await addDocs({foo: 'a'}, {foo: 'b'}).then(async () => { | ||
| const stream = randomCol.orderBy('foo').offset(1).stream(); | ||
| for await (const doc of stream) { | ||
| expect(doc).to.be.an.instanceOf(QueryDocumentSnapshot); | ||
| ++received; | ||
| } | ||
|
|
||
| expect(received).to.equal(1); | ||
| }); |
No description provided.