Skip to content

Commit f10b4fb

Browse files
committed
refactor: use async/await, const and arrow function
1 parent 032d97a commit f10b4fb

1 file changed

Lines changed: 59 additions & 61 deletions

File tree

Lines changed: 59 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict';
22

3-
describe('test.type.js', function () {
4-
var sortById = testUtils.sortById;
3+
describe('test.type.js', () => {
4+
const sortById = testUtils.sortById;
55

6-
beforeEach(function () {
7-
var db = context.db;
8-
return db.bulkDocs([
6+
beforeEach(async () => {
7+
const db = context.db;
8+
await db.bulkDocs([
99
{_id: 'a', foo: 'bar'},
1010
{_id: 'b', foo: 1},
1111
{_id: 'c', foo: null},
@@ -15,107 +15,105 @@ describe('test.type.js', function () {
1515
]);
1616
});
1717

18-
it('does null', function () {
19-
var db = context.db;
20-
return db.find({
18+
it('does null', async () => {
19+
const db = context.db;
20+
const res = await db.find({
2121
selector: {
2222
'foo': {$type: 'null'}
2323
},
2424
fields: ['_id']
25-
}).then(function (res) {
26-
res.docs.sort(sortById);
27-
res.docs.should.deep.equal([{_id: 'c'}]);
2825
});
26+
res.docs.sort(sortById);
27+
res.docs.should.deep.equal([{_id: 'c'}]);
2928
});
3029

31-
it('does boolean', function () {
32-
var db = context.db;
33-
return db.find({
30+
it('does boolean', async () => {
31+
const db = context.db;
32+
const res = await db.find({
3433
selector: {
3534
'foo': {$type: 'boolean'}
3635
},
3736
fields: ['_id']
38-
}).then(function (res) {
39-
res.docs.sort(sortById);
40-
res.docs.should.deep.equal([{_id: 'f'}]);
41-
4237
});
38+
res.docs.sort(sortById);
39+
res.docs.should.deep.equal([{_id: 'f'}]);
4340
});
4441

45-
it('does number', function () {
46-
var db = context.db;
47-
return db.find({
42+
it('does number', async () => {
43+
const db = context.db;
44+
const res = await db.find({
4845
selector: {
4946
'foo': {$type: 'number'}
5047
},
5148
fields: ['_id']
52-
}).then(function (res) {
53-
res.docs.sort(sortById);
54-
res.docs.should.deep.equal([{_id: 'b'}]);
5549
});
50+
res.docs.sort(sortById);
51+
res.docs.should.deep.equal([{_id: 'b'}]);
5652
});
5753

58-
it('does string', function () {
59-
var db = context.db;
60-
return db.find({
54+
it('does string', async () => {
55+
const db = context.db;
56+
const res = await db.find({
6157
selector: {
6258
'foo': {$type: 'string'}
6359
},
6460
fields: ['_id']
65-
}).then(function (res) {
66-
res.docs.sort(sortById);
67-
res.docs.should.deep.equal([{_id: 'a'}]);
6861
});
62+
res.docs.sort(sortById);
63+
res.docs.should.deep.equal([{_id: 'a'}]);
6964
});
7065

71-
it('does array', function () {
72-
var db = context.db;
73-
return db.find({
66+
it('does array', async () => {
67+
const db = context.db;
68+
const res = await db.find({
7469
selector: {
7570
'foo': {$type: 'array'}
7671
},
7772
fields: ['_id']
78-
}).then(function (res) {
79-
res.docs.sort(sortById);
80-
res.docs.should.deep.equal([{_id: 'd'}]);
8173
});
74+
res.docs.sort(sortById);
75+
res.docs.should.deep.equal([{_id: 'd'}]);
8276
});
8377

84-
it('does object', function () {
85-
var db = context.db;
86-
return db.find({
78+
it('does object', async () => {
79+
const db = context.db;
80+
const res = await db.find({
8781
selector: {
8882
'foo': {$type: 'object'}
8983
},
9084
fields: ['_id']
91-
}).then(function (res) {
92-
res.docs.sort(sortById);
93-
res.docs.should.deep.equal([{_id: 'e'}]);
9485
});
86+
res.docs.sort(sortById);
87+
res.docs.should.deep.equal([{_id: 'e'}]);
9588
});
9689

97-
it('should error for unsupported query value', function () {
98-
var db = context.db;
99-
return db.find({
100-
selector: {
101-
'foo': {$type: 'made-up'}
102-
},
103-
fields: ['_id']
104-
}).catch(function (err) {
90+
it('should error for unsupported query value', async () => {
91+
const db = context.db;
92+
try {
93+
await db.find({
94+
selector: {
95+
'foo': {$type: 'made-up'}
96+
},
97+
fields: ['_id']
98+
});
99+
throw new Error('Function should throw');
100+
} catch (err) {
105101
err.message.should.eq('Query operator $type must be a string. Supported values: "null", "boolean", "number", "string", "array", or "object". Received string: made-up');
106-
});
102+
}
107103
});
108-
it('should error for non-string query value', function () {
109-
var db = context.db;
110-
return db.find({
111-
selector: {
112-
'foo': {$type: 0}
113-
},
114-
fields: ['_id']
115-
}).then(function () {
104+
105+
it('should error for non-string query value', async () => {
106+
const db = context.db;
107+
try {
108+
await db.find({
109+
selector: {
110+
'foo': {$type: 0}
111+
},
112+
fields: ['_id']
113+
});
116114
throw new Error('Function should throw');
117-
}, function (err) {
115+
} catch (err) {
118116
err.message.should.eq('Query operator $type must be a string. Supported values: "null", "boolean", "number", "string", "array", or "object". Received number: 0');
119-
});
117+
}
120118
});
121119
});

0 commit comments

Comments
 (0)