|
6 | 6 | * found in the LICENSE file at https://angular.io/license |
7 | 7 | */ |
8 | 8 |
|
9 | | -import {isNode, zoneSymbol} from '../../lib/common/utils'; |
| 9 | +import {isNode} from '../../lib/common/utils'; |
10 | 10 | import {ifEnvSupports} from '../test-util'; |
11 | 11 |
|
12 | 12 | declare const global: any; |
@@ -76,6 +76,12 @@ describe( |
76 | 76 | expect(new Promise(() => null) instanceof Promise).toBe(true); |
77 | 77 | }); |
78 | 78 |
|
| 79 | + it('Promise.resolve(subPromise) should equal to subPromise', () => { |
| 80 | + const p1 = Promise.resolve(1); |
| 81 | + const p2 = Promise.resolve(p1); |
| 82 | + expect(p1).toBe(p2); |
| 83 | + }); |
| 84 | + |
79 | 85 | xit('should ensure that Promise this is instanceof Promise', () => { |
80 | 86 | expect(() => { |
81 | 87 | Promise.call({} as any, () => null); |
@@ -130,6 +136,23 @@ describe( |
130 | 136 | expect(new MyPromise(() => {}).then(() => null) instanceof MyPromise).toBe(true); |
131 | 137 | }); |
132 | 138 |
|
| 139 | + it('should allow subclassing with own then', (done: DoneFn) => { |
| 140 | + class MyPromise extends Promise<any> { |
| 141 | + constructor(private sub: Promise<any>) { |
| 142 | + super((resolve) => {resolve(null)}); |
| 143 | + } |
| 144 | + |
| 145 | + override then(onFulfilled: any, onRejected: any) { |
| 146 | + return this.sub.then(onFulfilled, onRejected); |
| 147 | + } |
| 148 | + } |
| 149 | + const p = Promise.resolve(1); |
| 150 | + new MyPromise(p).then((v: any) => { |
| 151 | + expect(v).toBe(1); |
| 152 | + done(); |
| 153 | + }, () => done()); |
| 154 | + }); |
| 155 | + |
133 | 156 | it('Symbol.species should return ZoneAwarePromise', () => { |
134 | 157 | const empty = function() {}; |
135 | 158 | const promise = Promise.resolve(1); |
|
0 commit comments