From 159c00638c5eca2b98dc3adbb659f5d70370f91d Mon Sep 17 00:00:00 2001 From: Lance Ball Date: Tue, 6 Dec 2016 15:19:12 -0500 Subject: [PATCH] feat: return 'this' from CircuitBreaker.fallback --- lib/circuit.js | 1 + test/test.js | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/circuit.js b/lib/circuit.js index 7544eb15..b9ea8b38 100644 --- a/lib/circuit.js +++ b/lib/circuit.js @@ -122,6 +122,7 @@ class CircuitBreaker extends EventEmitter { */ fallback (func) { this[FALLBACK_FUNCTION] = func; + return this; } /** diff --git a/test/test.js b/test/test.js index 9cbc72ba..f1e46dec 100644 --- a/test/test.js +++ b/test/test.js @@ -172,6 +172,17 @@ test('Passes arguments to the fallback function', (t) => { }); }); +test('Returns self from fallback()', (t) => { + circuitBreaker(passFail, { maxFailures: 1 }) + .fallback(() => {}) + .fire(1) + .then((result) => { + t.equals(result, 1); + }) + .then(t.end) + .catch(t.fail); +}); + test('CircuitBreaker status', (t) => { const breaker = circuitBreaker(passFail, { maxFailures: 1 }); const deepEqual = (t, expected) => (actual) => t.deepEqual(actual, expected);