summaryrefslogtreecommitdiff
path: root/test/asyncify.js
diff options
context:
space:
mode:
authorAlex Early <alexander.early@gmail.com>2018-07-08 16:58:36 -0700
committerGitHub <noreply@github.com>2018-07-08 16:58:36 -0700
commite4751178540a3c6e64598b93977481ec599704d2 (patch)
treedce5731bdb1076971d2e4a0a42fbe0d95c720185 /test/asyncify.js
parent6405b109fe60541ff42d7638ac891d321d6a7bb3 (diff)
downloadasync-e4751178540a3c6e64598b93977481ec599704d2.tar.gz
ES6-ify codebase (#1553)
* cancelable foreach * cancelable waterfall * cancellable auto * fix lint * fix tests * cancelable whilst/until/during/forever * fix waterfall test. It WILL get there * docs * use rest params instead of slice * clean up internals * remove property func * clarify uses of createTester * happy path async funtions in asyncify * stop using arguments * DLL to class * moar arrows * fix merge issues * remove forOwn * moar arrows * fix merge mistake * even more arrows, what can stop him * mo more fn.apply(null,...) * remove more spurious uses of apply * update lint config * just when you thought there couldn't possibly be more arrows * use eslint:recommended * even less uses or aguments * get rid of prototype cuteness * fix concat tests * fix more tests
Diffstat (limited to 'test/asyncify.js')
-rw-r--r--test/asyncify.js69
1 files changed, 34 insertions, 35 deletions
diff --git a/test/asyncify.js b/test/asyncify.js
index 112b8ad..14f35ee 100644
--- a/test/asyncify.js
+++ b/test/asyncify.js
@@ -2,32 +2,31 @@ var async = require('../lib');
var assert = require('assert');
var expect = require('chai').expect;
-describe('asyncify', function(){
+describe('asyncify', () => {
- it('asyncify', function(done) {
+ it('asyncify', (done) => {
var parse = async.asyncify(JSON.parse);
- parse("{\"a\":1}", function (err, result) {
+ parse("{\"a\":1}", (err, result) => {
assert(!err);
expect(result.a).to.equal(1);
done();
});
});
- it('asyncify null', function(done) {
- var parse = async.asyncify(function() {
+ it('asyncify null', (done) => {
+ var parse = async.asyncify(() => {
return null;
});
- parse("{\"a\":1}", function (err, result) {
+ parse("{\"a\":1}", (err, result) => {
assert(!err);
expect(result).to.equal(null);
done();
});
});
- it('variable numbers of arguments', function(done) {
- async.asyncify(function (/*x, y, z*/) {
- return arguments;
- })(1, 2, 3, function (err, result) {
+ it('variable numbers of arguments', (done) => {
+ const fn = (...args/*x, y, z*/) => args
+ async.asyncify(fn)(1, 2, 3, (err, result) => {
expect(result.length).to.equal(3);
expect(result[0]).to.equal(1);
expect(result[1]).to.equal(2);
@@ -36,19 +35,19 @@ describe('asyncify', function(){
});
});
- it('catch errors', function(done) {
- async.asyncify(function () {
+ it('catch errors', (done) => {
+ async.asyncify(() => {
throw new Error("foo");
- })(function (err) {
+ })((err) => {
assert(err);
expect(err.message).to.equal("foo");
done();
});
});
- it('dont catch errors in the callback', function(done) {
+ it('dont catch errors in the callback', (done) => {
try {
- async.asyncify(function () {})(function (err) {
+ async.asyncify(() => {})((err) => {
if (err) {
return done(new Error("should not get an error here"));
}
@@ -60,17 +59,17 @@ describe('asyncify', function(){
}
});
- describe('promisified', function() {
+ describe('promisified', () => {
function promisifiedTests(Promise) {
- it('resolve', function(done) {
+ it('resolve', (done) => {
var promisified = function(argument) {
- return new Promise(function (resolve) {
- setTimeout(function () {
+ return new Promise(((resolve) => {
+ setTimeout(() => {
resolve(argument + " resolved");
}, 15);
- });
+ }));
};
- async.asyncify(promisified)("argument", function (err, value) {
+ async.asyncify(promisified)("argument", (err, value) => {
if (err) {
return done(new Error("should not get an error here"));
}
@@ -79,42 +78,42 @@ describe('asyncify', function(){
});
});
- it('reject', function(done) {
+ it('reject', (done) => {
var promisified = function(argument) {
- return new Promise(function (resolve, reject) {
+ return new Promise(((resolve, reject) => {
reject(argument + " rejected");
- });
+ }));
};
- async.asyncify(promisified)("argument", function (err) {
+ async.asyncify(promisified)("argument", (err) => {
assert(err);
expect(err.message).to.equal("argument rejected");
done();
});
});
- it('callback error @nodeonly', function(done) {
+ it('callback error @nodeonly', (done) => {
expectUncaughtException();
var promisified = function(argument) {
- return new Promise(function (resolve) {
+ return new Promise(((resolve) => {
resolve(argument + " resolved");
- });
+ }));
};
var call_count = 0;
- async.asyncify(promisified)("argument", function () {
+ async.asyncify(promisified)("argument", () => {
call_count++;
if (call_count === 1) {
throw new Error("error in callback");
}
});
- setTimeout(function () {
+ setTimeout(() => {
expect(call_count).to.equal(1);
done();
}, 15);
});
- it('dont catch errors in the callback @nodeonly', function(done) {
+ it('dont catch errors in the callback @nodeonly', (done) => {
expectUncaughtException(checkErr);
var callbackError = new Error('thrown from callback');
@@ -127,7 +126,7 @@ describe('asyncify', function(){
throw callbackError;
}
- async.asyncify(function () {
+ async.asyncify(() => {
return Promise.reject(new Error('rejection'));
})(callback);
});
@@ -142,7 +141,7 @@ describe('asyncify', function(){
var Promise = require('bluebird');
// Bluebird reports unhandled rejections to stderr. We handle it because we expect
// unhandled rejections:
- Promise.onPossiblyUnhandledRejection(function ignoreRejections() {});
+ Promise.onPossiblyUnhandledRejection(() => {});
promisifiedTests.call(this, Promise);
});
@@ -160,8 +159,8 @@ describe('asyncify', function(){
// do a weird dance to catch the async thrown error before mocha
var listeners = process.listeners('uncaughtException');
process.removeAllListeners('uncaughtException');
- process.once('uncaughtException', function onErr(err) {
- listeners.forEach(function(listener) {
+ process.once('uncaughtException', (err) => {
+ listeners.forEach((listener) => {
process.on('uncaughtException', listener);
});
// can't throw errors in a uncaughtException handler, defer