-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from r24y/feat/no-proxy
New: Add `no-proxy` version for usage in Node 4
- Loading branch information
Showing
3 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
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 promise = myFn.anticipated.nextCall | ||
.then(() => { | ||
expect(spy).toHaveBeenCalledTimes(1); | ||
}); | ||
expect(spy).not.toHaveBeenCalled(); | ||
myFn(); | ||
expect(spy).toHaveBeenCalledTimes(1); | ||
}); | ||
test('should return a new Promise', () => { | ||
const myFn = anticipatedCall(); | ||
const promise1 = myFn.anticipated.nextCall; | ||
const promise2 = myFn.anticipated.nextCall; | ||
expect(promise1).not.toBe(promise2); | ||
}); | ||
test('should handle subsequent calls as expected', () => { | ||
const spy = jest.fn(); | ||
const myFn = anticipatedCall(spy); | ||
|
||
const promise1 = myFn.anticipated.nextCall; | ||
|
||
myFn(); | ||
|
||
return promise1.then(() => { | ||
expect(spy).toHaveBeenCalledTimes(1); | ||
|
||
const promise2 = myFn.anticipated.nextCall; | ||
myFn(); | ||
return promise2; | ||
}).then(() => { | ||
expect(spy).toHaveBeenCalledTimes(2); | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const {Anticipated, noop} = require('./index'); | ||
|
||
function anticipateCallWithoutProxy(fn) { | ||
const anticipated = new Anticipated(); | ||
function proxiedCall(...args) { | ||
return anticipated.apply(fn, this, args); | ||
} | ||
proxiedCall.anticipated = anticipated; | ||
return proxiedCall; | ||
} | ||
|
||
module.exports = anticipateCallWithoutProxy; |