deno.land / x / mongoose@6.7.5 / test / docs / asyncIterator.test.js

asyncIterator.test.js
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
'use strict';
/** * Module dependencies. */
const assert = require('assert');const start = require('../common');
const mongoose = start.mongoose;
describe('asyncIterator', function() { let db; let Movie;
before(async function() { db = await start();
const schema = new mongoose.Schema({ name: String }); await db.dropCollection('Movie').catch(() => {}); db.deleteModel(/Movie/); Movie = db.model('Movie', schema);
await Movie.create([ { name: 'Kickboxer' }, { name: 'Ip Man' }, { name: 'Enter the Dragon' } ]); });
after(async function() { await db.close(); });
function wait() { return new Promise(resolve => setTimeout(resolve, 0)); }
it('supports for/await/of on a query (gh-6737)', async function() { let names = []; for await (const doc of Movie.find().sort({ name: 1 })) { await wait(); names.push(doc.name); }
assert.deepEqual(names, ['Enter the Dragon', 'Ip Man', 'Kickboxer']); });
it('supports for/await/of on a aggregation (gh-6737)', async function() { let names = []; for await (const doc of Movie.aggregate([{ $sort: { name: -1 } }])) { await wait(); names.push(doc.name); }
assert.deepEqual(names, ['Kickboxer', 'Ip Man', 'Enter the Dragon']); });
it('supports for/await/of on a query cursor (gh-9403)', async function() { let names = []; const cursor = Movie.find().sort({ name: -1 }).cursor(); for await (const doc of cursor) { await wait(); names.push(doc.name); }
assert.deepEqual(names, ['Kickboxer', 'Ip Man', 'Enter the Dragon']); });
it('supports for/await/of on a aggregation cursor (gh-9403)', async function() { let names = []; const cursor = Movie.aggregate([{ $sort: { name: -1 } }]).cursor(); for await (const doc of cursor) { await wait(); names.push(doc.name); }
assert.deepEqual(names, ['Kickboxer', 'Ip Man', 'Enter the Dragon']); });});
mongoose

Version Info

Tagged at
a year ago