-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Wait for all handled requests to resolve via
.flush()
(#75)
- Loading branch information
1 parent
2c0083e
commit a3113b7
Showing
12 changed files
with
256 additions
and
22 deletions.
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
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
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
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
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,16 @@ | ||
/** | ||
* Create a deferred promise with `resolve` and `reject` methods. | ||
*/ | ||
export default class DeferredPromise extends Promise { | ||
constructor() { | ||
let resolve, reject; | ||
|
||
super((_resolve, _reject) => { | ||
resolve = _resolve; | ||
reject = _reject; | ||
}); | ||
|
||
this.resolve = resolve; | ||
this.reject = reject; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
packages/@pollyjs/core/tests/unit/utils/deferred-promise-test.js
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,29 @@ | ||
import DeferredPromise from '../../../src/utils/deferred-promise'; | ||
|
||
describe('Unit | Utils | DeferredPromise', function() { | ||
it('should exist', function() { | ||
expect(DeferredPromise).to.be.a('function'); | ||
expect(new DeferredPromise().resolve).to.be.a('function'); | ||
expect(new DeferredPromise().reject).to.be.a('function'); | ||
}); | ||
|
||
it('should resolve when calling .resolve()', async function() { | ||
const promise = new DeferredPromise(); | ||
|
||
promise.resolve(42); | ||
expect(await promise).to.equal(42); | ||
}); | ||
|
||
it('should reject when calling .reject()', async function() { | ||
const promise = new DeferredPromise(); | ||
|
||
promise.reject(new Error('42')); | ||
|
||
try { | ||
await promise; | ||
} catch (error) { | ||
expect(error).to.be.an('error'); | ||
expect(error.message).to.equal('42'); | ||
} | ||
}); | ||
}); |
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
Oops, something went wrong.