1+ import $allKeyed from '@core-js/pure/full/promise/all-keyed' ;
12import Promise from '@core-js/pure/full/promise' ;
23import Symbol from '@core-js/pure/full/symbol' ;
34import Object from '@core-js/pure/full/object' ;
@@ -8,15 +9,6 @@ QUnit.test('Promise.allKeyed', assert => {
89 assert . true ( Promise . allKeyed ( { } ) instanceof Promise , 'returns a promise' ) ;
910} ) ;
1011
11- QUnit . test ( 'Promise.allKeyed, rejected on incorrect input' , assert => {
12- return Promise . allKeyed ( 'string' ) . then ( ( ) => {
13- assert . avoid ( ) ;
14- } , error => {
15- assert . true ( error instanceof TypeError , 'error is TypeError' ) ;
16- assert . required ( 'rejected as expected' ) ;
17- } ) ;
18- } ) ;
19-
2012QUnit . test ( 'Promise.allKeyed, resolved' , assert => {
2113 return Promise . allKeyed ( {
2214 a : Promise . resolve ( 1 ) ,
@@ -58,6 +50,15 @@ QUnit.test('Promise.allKeyed, resolved with hidden attributes', assert => {
5850 } ) ;
5951} ) ;
6052
53+ QUnit . test ( 'Promise.allKeyed, rejected on incorrect input' , assert => {
54+ return Promise . allKeyed ( 'string' ) . then ( ( ) => {
55+ assert . avoid ( ) ;
56+ } , error => {
57+ assert . true ( error instanceof TypeError , 'error is TypeError' ) ;
58+ assert . required ( 'rejected as expected' ) ;
59+ } ) ;
60+ } ) ;
61+
6162QUnit . test ( 'Promise.allKeyed, resolved with timeouts' , assert => {
6263 return Promise . allKeyed ( {
6364 a : Promise . resolve ( 1 ) ,
@@ -72,6 +73,64 @@ QUnit.test('Promise.allKeyed, resolved with timeouts', assert => {
7273 } ) ;
7374} ) ;
7475
76+ QUnit . test ( 'Promise.allKeyed, subclassing' , assert => {
77+ const { allKeyed, resolve } = Promise ;
78+ function SubPromise ( executor ) {
79+ executor ( ( ) => { /* empty */ } , ( ) => { /* empty */ } ) ;
80+ }
81+ SubPromise . resolve = resolve . bind ( Promise ) ;
82+ assert . true ( allKeyed . call ( SubPromise , { a : Promise . resolve ( 1 ) } ) instanceof SubPromise , 'subclassing, `this` pattern' ) ;
83+
84+ function FakePromise1 ( ) { /* empty */ }
85+ function FakePromise2 ( executor ) {
86+ executor ( null , ( ) => { /* empty */ } ) ;
87+ }
88+ function FakePromise3 ( executor ) {
89+ executor ( ( ) => { /* empty */ } , null ) ;
90+ }
91+ FakePromise1 . resolve = FakePromise2 . resolve = FakePromise3 . resolve = resolve . bind ( Promise ) ;
92+ assert . throws ( ( ) => {
93+ allKeyed . call ( FakePromise1 , { a : Promise . resolve ( 1 ) } ) ;
94+ } , 'NewPromiseCapability validations, #1' ) ;
95+ assert . throws ( ( ) => {
96+ allKeyed . call ( FakePromise2 , { a : Promise . resolve ( 1 ) } ) ;
97+ } , 'NewPromiseCapability validations, #2' ) ;
98+ assert . throws ( ( ) => {
99+ allKeyed . call ( FakePromise3 , { a : Promise . resolve ( 1 ) } ) ;
100+ } , 'NewPromiseCapability validations, #3' ) ;
101+ } ) ;
102+
103+ QUnit . test ( 'Promise.allKeyed, without constructor context' , assert => {
104+ const { allKeyed } = Promise ;
105+ assert . throws ( ( ) => allKeyed ( { a : Promise . resolve ( 1 ) } ) , TypeError , 'Throws if called without a constructor context' ) ;
106+ assert . throws ( ( ) => allKeyed . call ( null , { a : Promise . resolve ( 1 ) } ) , TypeError , 'Throws if called with null as this' ) ;
107+ } ) ;
108+
109+ QUnit . test ( 'Promise.allKeyed, method from direct entry, without constructor context' , assert => {
110+ return $allKeyed ( { a : Promise . resolve ( 1 ) } ) . then ( it => {
111+ assert . deepEqual ( it , { a : 1 } , 'resolved with a correct value' ) ;
112+ } ) ;
113+ } ) ;
114+
115+ QUnit . test ( 'Promise.allKeyed, method from direct entry, with null context' , assert => {
116+ return $allKeyed . call ( null , { a : Promise . resolve ( 1 ) } ) . then ( it => {
117+ assert . deepEqual ( it , { a : 1 } , 'resolved with a correct value' ) ;
118+ } ) ;
119+ } ) ;
120+
121+ QUnit . test ( 'Promise.allKeyed, result object has null prototype' , assert => {
122+ return Promise . allKeyed ( {
123+ a : Promise . resolve ( 1 ) ,
124+ b : Promise . resolve ( 2 ) ,
125+ } ) . then ( result => {
126+ assert . strictEqual (
127+ Object . getPrototypeOf ( result ) ,
128+ null ,
129+ 'Result object has null prototype' ,
130+ ) ;
131+ } ) ;
132+ } ) ;
133+
75134QUnit . test ( 'Promise.allKeyed, symbol keys' , assert => {
76135 const symA = Symbol ( 'A' ) ;
77136 const symB = Symbol ( 'B' ) ;
@@ -96,28 +155,3 @@ QUnit.test('Promise.allKeyed, keys order', assert => {
96155 assert . deepEqual ( actualKeys , [ 'a' , 'b' , 'c' ] , 'correct order in the case when promises resolves in different order' ) ;
97156 } ) ;
98157} ) ;
99-
100- QUnit . test ( 'Promise.allKeyed, fake promises' , assert => {
101- const { allKeyed } = Promise ;
102- const FakePromise1 = function ( executor ) {
103- executor ( ( ) => { /* empty */ } , ( ) => { /* empty */ } ) ;
104- } ;
105- const FakePromise2 = FakePromise1 [ Symbol . species ] = function ( executor ) {
106- executor ( ( ) => { /* empty */ } , ( ) => { /* empty */ } ) ;
107- } ;
108- FakePromise1 . resolve = FakePromise2 . resolve = Promise . resolve . bind ( Promise ) ;
109- assert . true ( allKeyed . call ( FakePromise1 , { a : Promise . resolve ( 1 ) } ) instanceof FakePromise1 , 'subclassing, `this` pattern' ) ;
110- } ) ;
111-
112- QUnit . test ( 'Promise.allKeyed, result object has null prototype' , assert => {
113- return Promise . allKeyed ( {
114- a : Promise . resolve ( 1 ) ,
115- b : Promise . resolve ( 2 ) ,
116- } ) . then ( result => {
117- assert . strictEqual (
118- Object . getPrototypeOf ( result ) ,
119- null ,
120- 'Result object has null prototype' ,
121- ) ;
122- } ) ;
123- } ) ;
0 commit comments