|
@@ -0,0 +1,25 @@
|
|
|
+import promisify from '../promisify';
|
|
|
+
|
|
|
+const asyncFunction = (a, callback) => {
|
|
|
+ if (a === 1) {
|
|
|
+ callback('error');
|
|
|
+ } else {
|
|
|
+ callback(null, 'data')
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+export default test => {
|
|
|
+ test.ok(typeof promisify === 'function', 'promisify should be a function');
|
|
|
+
|
|
|
+ const promisified = promisify(asyncFunction);
|
|
|
+
|
|
|
+ promisified(1).catch((err) => {
|
|
|
+ test.ok(err === 'error', 'error should be thrown');
|
|
|
+ });
|
|
|
+
|
|
|
+ promisified(0).then((data) => {
|
|
|
+ test.ok(data === 'data', 'data should be resolved')
|
|
|
+ });
|
|
|
+
|
|
|
+ test.done();
|
|
|
+};
|