Created
June 12, 2017 11:38
-
-
Save adrienlucas/e4c25f0eb3c1ecffa27a0a7798a898db to your computer and use it in GitHub Desktop.
jQuery Thenable stacking POC
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
import jQuery from 'jquery'; | |
it('stacks several promises with one rejection', () => { | |
const p1 = new jQuery.Deferred(); | |
const p2 = new jQuery.Deferred(); | |
const p3 = new jQuery.Deferred(); | |
const stack = jQuery.when(...promises); | |
expect(stack.state()).toBe('pending'); | |
p3.resolve(); | |
expect(stack.state()).toBe('pending'); | |
p2.reject(); | |
expect(stack.state()).toBe('rejected'); | |
p1.resolve(); | |
expect(stack.state()).toBe('rejected'); | |
}); | |
it('stacks several promises with no rejection', () => { | |
const p1 = new jQuery.Deferred(); | |
const p2 = new jQuery.Deferred(); | |
const p3 = new jQuery.Deferred(); | |
const stack = jQuery.when(...promises); | |
expect(stack.state()).toBe('pending'); | |
p3.resolve(); | |
expect(stack.state()).toBe('pending'); | |
p2.resolve(); | |
expect(stack.state()).toBe('pending'); | |
p1.resolve(); | |
expect(stack.state()).toBe('resolved'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment