-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
44 lines (34 loc) · 930 Bytes
/
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
'use strict';
const assert = require('assert');
const Promisify = require('.');
// Test a promise that returns a single value
function sum (a, b, callback) {
callback(null, a + b);
}
let sumPromise = Promisify(sum);
// Test return of multiple values
function multCallbacker (a, b, callback) {
callback(null, a, b);
}
let multCallbackerPromise = Promisify(multCallbacker);
// Test binding of methods inside objects
class Bindable {
constructor () {
this._prop = 3;
}
get prop () {
return this._prop;
}
increment (callback) {
this._prop += 1;
callback(null, this.prop);
}
}
let bindable = new Bindable();
let incrementPromise = Promisify(bindable.increment, bindable);
async function main () {
assert((await sumPromise(2, 2)) === 4);
assert((await multCallbackerPromise('a', 'b'))[1] === 'b');
assert((await incrementPromise()) === 4);
}
main();