summaryrefslogtreecommitdiff
path: root/test/memoize.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/memoize.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/memoize.js')
-rw-r--r--test/memoize.js94
1 files changed, 47 insertions, 47 deletions
diff --git a/test/memoize.js b/test/memoize.js
index 2cadafd..b2c11b3 100644
--- a/test/memoize.js
+++ b/test/memoize.js
@@ -2,25 +2,25 @@ var async = require('../lib');
var expect = require('chai').expect;
var assert = require('assert');
-describe("memoize", function() {
+describe("memoize", () => {
- it('memoize', function(done) {
+ it('memoize', (done) => {
var call_order = [];
var fn = function (arg1, arg2, callback) {
- async.setImmediate(function () {
+ async.setImmediate(() => {
call_order.push(['fn', arg1, arg2]);
callback(null, arg1 + arg2);
});
};
var fn2 = async.memoize(fn);
- fn2(1, 2, function (err, result) {
+ fn2(1, 2, (err, result) => {
assert(err === null, err + " passed instead of 'null'");
expect(result).to.equal(3);
- fn2(1, 2, function (err, result) {
+ fn2(1, 2, (err, result) => {
expect(result).to.equal(3);
- fn2(2, 2, function (err, result) {
+ fn2(2, 2, (err, result) => {
expect(result).to.equal(4);
expect(call_order).to.eql([['fn',1,2], ['fn',2,2]]);
done();
@@ -29,21 +29,21 @@ describe("memoize", function() {
});
});
- it('maintains asynchrony', function(done) {
+ it('maintains asynchrony', (done) => {
var call_order = [];
var fn = function (arg1, arg2, callback) {
call_order.push(['fn', arg1, arg2]);
- async.setImmediate(function () {
+ async.setImmediate(() => {
call_order.push(['cb', arg1, arg2]);
callback(null, arg1 + arg2);
});
};
var fn2 = async.memoize(fn);
- fn2(1, 2, function (err, result) {
+ fn2(1, 2, (err, result) => {
expect(result).to.equal(3);
- fn2(1, 2, function (err, result) {
+ fn2(1, 2, (err, result) => {
expect(result).to.equal(3);
async.nextTick(memoize_done);
call_order.push('tick3');
@@ -57,9 +57,9 @@ describe("memoize", function() {
['fn',1,2], // initial async call
'tick1', // async caller
['cb',1,2], // async callback
- // ['fn',1,2], // memoized // memoized async body
+ // ['fn',1,2], // memoized // memoized async body
'tick2', // handler for first async call
- // ['cb',1,2], // memoized // memoized async response body
+ // ['cb',1,2], // memoized // memoized async response body
'tick3' // handler for memoized async call
];
expect(call_order).to.eql(async_call_order);
@@ -67,23 +67,23 @@ describe("memoize", function() {
}
});
- it('unmemoize', function(done) {
+ it('unmemoize', (done) => {
var call_order = [];
var fn = function (arg1, arg2, callback) {
call_order.push(['fn', arg1, arg2]);
- async.setImmediate(function () {
+ async.setImmediate(() => {
callback(null, arg1 + arg2);
});
};
var fn2 = async.memoize(fn);
var fn3 = async.unmemoize(fn2);
- fn3(1, 2, function (err, result) {
+ fn3(1, 2, (err, result) => {
expect(result).to.equal(3);
- fn3(1, 2, function (err, result) {
+ fn3(1, 2, (err, result) => {
expect(result).to.equal(3);
- fn3(2, 2, function (err, result) {
+ fn3(2, 2, (err, result) => {
expect(result).to.equal(4);
expect(call_order).to.eql([['fn',1,2], ['fn',1,2], ['fn',2,2]]);
done();
@@ -92,40 +92,40 @@ describe("memoize", function() {
});
});
- it('unmemoize a not memoized function', function(done) {
+ it('unmemoize a not memoized function', (done) => {
var fn = function (arg1, arg2, callback) {
callback(null, arg1 + arg2);
};
var fn2 = async.unmemoize(fn);
- fn2(1, 2, function(err, result) {
+ fn2(1, 2, (err, result) => {
expect(result).to.equal(3);
done();
});
});
- it('error', function(done) {
+ it('error', (done) => {
var testerr = new Error('test');
var fn = function (arg1, arg2, callback) {
callback(testerr, arg1 + arg2);
};
- async.memoize(fn)(1, 2, function (err) {
+ async.memoize(fn)(1, 2, (err) => {
expect(err).to.equal(testerr);
done();
});
});
- it('should not memoize result if error occurs', function(done) {
+ it('should not memoize result if error occurs', (done) => {
var testerr = new Error('test');
var fn = function (arg1, arg2, callback) {
callback(testerr, arg1 + arg2);
};
var memoized = async.memoize(fn);
- memoized(1, 2, function (err) {
+ memoized(1, 2, (err) => {
expect(err).to.equal(testerr);
testerr = null;
- memoized(1, 3, function (err, result) {
+ memoized(1, 3, (err, result) => {
expect(err).to.equal(null);
expect(result).to.equal(4);
done();
@@ -133,63 +133,63 @@ describe("memoize", function() {
});
});
- it('multiple calls', function(done) {
+ it('multiple calls', (done) => {
var fn = function (arg1, arg2, callback) {
assert(true);
- setTimeout(function(){
+ setTimeout(() => {
callback(null, arg1, arg2);
}, 10);
};
var fn2 = async.memoize(fn);
- fn2(1, 2, function(err, result) {
+ fn2(1, 2, (err, result) => {
expect(result).to.equal(1, 2);
});
- fn2(1, 2, function(err, result) {
+ fn2(1, 2, (err, result) => {
expect(result).to.equal(1, 2);
done();
});
});
- it('custom hash function', function(done) {
+ it('custom hash function', (done) => {
var fn = function (arg1, arg2, callback) {
callback(null, arg1 + arg2);
};
- var fn2 = async.memoize(fn, function () {
+ var fn2 = async.memoize(fn, () => {
return 'custom hash';
});
- fn2(1, 2, function (err, result) {
+ fn2(1, 2, (err, result) => {
expect(result).to.equal(3);
- fn2(2, 2, function (err, result) {
+ fn2(2, 2, (err, result) => {
expect(result).to.equal(3);
done();
});
});
});
- it('manually added memo value', function(done) {
- var fn = async.memoize(function() {
+ it('manually added memo value', (done) => {
+ var fn = async.memoize(() => {
throw new Error("Function should never be called");
});
fn.memo.foo = ["bar"];
- fn("foo", function(val) {
+ fn("foo", (err, val) => {
expect(val).to.equal("bar");
done();
});
});
- it('avoid constructor key return undefined', function(done) {
- var fn = async.memoize(function(name, callback) {
- setTimeout(function(){
+ it('avoid constructor key return undefined', (done) => {
+ var fn = async.memoize((name, callback) => {
+ setTimeout(() => {
callback(null, name);
}, 100);
});
- fn('constructor', function(error, results) {
+ fn('constructor', (error, results) => {
expect(results).to.equal('constructor');
done();
});
});
- it('avoid __proto__ key return undefined', function(done) {
+ it('avoid __proto__ key return undefined', (done) => {
// Skip test if there is a Object.create bug (node 0.10 and some Chrome 30x versions)
var x = Object.create(null);
/* jshint proto: true */
@@ -198,24 +198,24 @@ describe("memoize", function() {
return done();
}
- var fn = async.memoize(function(name, callback) {
- setTimeout(function(){
+ var fn = async.memoize((name, callback) => {
+ setTimeout(() => {
callback(null, name);
}, 100);
});
- fn('__proto__', function(error, results) {
+ fn('__proto__', (error, results) => {
expect(results).to.equal('__proto__');
done();
});
});
- it('allow hasOwnProperty as key', function(done) {
- var fn = async.memoize(function(name, callback) {
- setTimeout(function(){
+ it('allow hasOwnProperty as key', (done) => {
+ var fn = async.memoize((name, callback) => {
+ setTimeout(() => {
callback(null, name);
}, 100);
});
- fn('hasOwnProperty', function(error, results) {
+ fn('hasOwnProperty', (error, results) => {
expect(results).to.equal('hasOwnProperty');
done();
});