From d47a3435b32d392ef4810914c43cf2f270766106 Mon Sep 17 00:00:00 2001 From: Ryan Kennedy Date: Tue, 17 Oct 2017 10:40:02 -0400 Subject: [PATCH] New: Permit access to original function in non-proxy use --- src/__tests__/no-proxy.test.js | 16 +++++++--------- src/no-proxy.js | 1 + 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/__tests__/no-proxy.test.js b/src/__tests__/no-proxy.test.js index 75286dd..cfe4099 100644 --- a/src/__tests__/no-proxy.test.js +++ b/src/__tests__/no-proxy.test.js @@ -3,16 +3,15 @@ const anticipatedCall = require('../no-proxy'); describe('no-proxy', () => { describe('nextCall', () => { test('should delay resolution until first call', () => { - const spy = jest.fn(); - const myFn = anticipatedCall(spy); + const myFn = anticipatedCall(jest.fn()); const promise = myFn.anticipated.nextCall .then(() => { - expect(spy).toHaveBeenCalledTimes(1); + expect(myFn.original).toHaveBeenCalledTimes(1); }); - expect(spy).not.toHaveBeenCalled(); + expect(myFn.original).not.toHaveBeenCalled(); myFn(); - expect(spy).toHaveBeenCalledTimes(1); + expect(myFn.original).toHaveBeenCalledTimes(1); }); test('should return a new Promise', () => { const myFn = anticipatedCall(); @@ -21,21 +20,20 @@ describe('no-proxy', () => { expect(promise1).not.toBe(promise2); }); test('should handle subsequent calls as expected', () => { - const spy = jest.fn(); - const myFn = anticipatedCall(spy); + const myFn = anticipatedCall(jest.fn()); const promise1 = myFn.anticipated.nextCall; myFn(); return promise1.then(() => { - expect(spy).toHaveBeenCalledTimes(1); + expect(myFn.original).toHaveBeenCalledTimes(1); const promise2 = myFn.anticipated.nextCall; myFn(); return promise2; }).then(() => { - expect(spy).toHaveBeenCalledTimes(2); + expect(myFn.original).toHaveBeenCalledTimes(2); }) }) }) diff --git a/src/no-proxy.js b/src/no-proxy.js index 7ae9be0..1b7642a 100644 --- a/src/no-proxy.js +++ b/src/no-proxy.js @@ -6,6 +6,7 @@ function anticipateCallWithoutProxy(fn) { return anticipated.apply(fn, this, args); } proxiedCall.anticipated = anticipated; + proxiedCall.original = fn; return proxiedCall; }