Browse Source

[promisify]: add test

mightyplow 7 years ago
parent
commit
0d18b75ae2
1 changed files with 25 additions and 0 deletions
  1. 25 0
      src/function/__tests__/promisify.test.js

+ 25 - 0
src/function/__tests__/promisify.test.js

@@ -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();
+};