From d8daddae371eed47062b4dd2f786312d9c5f1e2a Mon Sep 17 00:00:00 2001 From: Thodoris Greasidis Date: Mon, 23 Nov 2020 10:41:57 +0200 Subject: [PATCH] docs: Outline that crashed invocations are not cached (#116) --- README.md | 2 ++ test/index.js | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/README.md b/README.md index cfaa778..e68af90 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,8 @@ memoized("foo", 3, "bar"); memoized("foo", 3, "bar"); // Cache hit ``` +__Note__: Invocations that throw exceptions are not cached. + ### Configuration All below options can be applied in any combination diff --git a/test/index.js b/test/index.js index c33ab8e..aa1bee9 100644 --- a/test/index.js +++ b/test/index.js @@ -105,6 +105,30 @@ module.exports = function (t, a) { } }; }, + "Error": function () { + var i = 0, + e = new Error("Test"), + fn = function () { + ++i; + if (i < 3) throw e; + return 3; + }; + + fn = t(fn); + + a.throws(function () { + fn(); + }, "Test"); + a(i, 1, "Called once"); + a.throws(function () { + fn(); + }, "Test"); + a(i, 2, "Called twice"); + a(fn(), 3, "First"); + a(fn(), 3, "Second"); + a(fn(), 3, "Third"); + a(i, 3, "Called three times"); + }, "Normalizer function": function () { var i = 0, fn = function () {