|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 |
| -const { Future } = require('..'); |
| 3 | +const { Future, futurify } = require('..'); |
4 | 4 | const metatests = require('metatests');
|
5 | 5 |
|
6 | 6 | metatests.test('Future map/fork', async test => {
|
@@ -90,3 +90,37 @@ metatests.test('Future stateless', async test => {
|
90 | 90 |
|
91 | 91 | test.end();
|
92 | 92 | });
|
| 93 | + |
| 94 | +metatests.test('Future futurify success', async test => { |
| 95 | + const f1 = (a, b, callback) => { |
| 96 | + if (typeof a !== 'number' || typeof b !== 'number') { |
| 97 | + callback(new Error('Arguments must be numbers')); |
| 98 | + return; |
| 99 | + } |
| 100 | + callback(null, a + b); |
| 101 | + }; |
| 102 | + |
| 103 | + const f2 = futurify(f1); |
| 104 | + |
| 105 | + f2(10, 20).fork(value => { |
| 106 | + test.strictSame(value, 30); |
| 107 | + test.end(); |
| 108 | + }); |
| 109 | +}); |
| 110 | + |
| 111 | +metatests.test('Future futurify fail', async test => { |
| 112 | + const f1 = (a, b, callback) => { |
| 113 | + if (typeof a !== 'number' || typeof b !== 'number') { |
| 114 | + callback(new Error('Arguments must be numbers')); |
| 115 | + return; |
| 116 | + } |
| 117 | + callback(null, a + b); |
| 118 | + }; |
| 119 | + |
| 120 | + const f2 = futurify(f1); |
| 121 | + |
| 122 | + f2('10', '20').fork(test.mustNotCall, error => { |
| 123 | + test.strictSame(error.message, 'Arguments must be numbers'); |
| 124 | + test.end(); |
| 125 | + }); |
| 126 | +}); |
0 commit comments