Skip to content

Commit

Permalink
Merge pull request #2 from r24y/feat/no-proxy
Browse files Browse the repository at this point in the history
New: Permit access to original function in non-proxy use
  • Loading branch information
ryaninvents authored Oct 17, 2017
2 parents 1294544 + d47a343 commit 134dbab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/__tests__/no-proxy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
})
})
})
Expand Down
1 change: 1 addition & 0 deletions src/no-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function anticipateCallWithoutProxy(fn) {
return anticipated.apply(fn, this, args);
}
proxiedCall.anticipated = anticipated;
proxiedCall.original = fn;
return proxiedCall;
}

Expand Down

0 comments on commit 134dbab

Please sign in to comment.