fix: implement Symbol.specics of Promise (#34162)

Close #34105, #33989

PR Close #34162
This commit is contained in:
JiaLiPassion
2019-12-01 12:27:33 +09:00
committed by Miško Hevery
parent 6b1a47183d
commit 539d8f09e0
2 changed files with 26 additions and 6 deletions

View File

@ -103,11 +103,21 @@ describe(
}).toThrowError('Must be an instanceof Promise.');
});
xit('should allow subclassing', () => {
it('should allow subclassing with Promise.specices', () => {
class MyPromise extends Promise<any> {
constructor(fn: any) { super(fn); }
static get[Symbol.species]() { return MyPromise; }
}
expect(new MyPromise(null).then(() => null) instanceof MyPromise).toBe(true);
expect(new MyPromise(() => {}).then(() => null) instanceof MyPromise).toBe(true);
});
it('Promise.specices should return ZoneAwarePromise', () => {
const empty = function() {};
const promise = Promise.resolve(1);
const FakePromise = ((promise.constructor = {} as any) as any)[Symbol.species] = function(
exec: any) { exec(empty, empty); };
expect(promise.then(empty) instanceof FakePromise).toBe(true);
});
it('should intercept scheduling of resolution and then', (done) => {