Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
jQuery Thenable stacking POC
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