From 58d7404ee4a0a205647cbe558d63dc352b71a214 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 5 Sep 2015 09:14:38 -0700 Subject: [PATCH] Add a `_.memoize` test for the `this` binding of `resolver`. --- test/test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/test.js b/test/test.js index 9ac313e81..d6ce4c1b9 100644 --- a/test/test.js +++ b/test/test.js @@ -9963,6 +9963,18 @@ strictEqual(memoized(1, 3, 5), 9); }); + test('should use `this` binding of function for `resolver`', 2, function() { + var fn = function(a, b, c) { return a + this.b + this.c; }, + memoized = _.memoize(fn, fn); + + var object = { 'b': 2, 'c': 3, 'memoized': memoized }; + strictEqual(object.memoized(1), 6); + + object.b = 3; + object.c = 5; + strictEqual(object.memoized(1), 9); + }); + test('should throw a TypeError if `resolve` is truthy and not a function', function() { raises(function() { _.memoize(_.noop, {}); }, TypeError); });