@@ -6,15 +6,59 @@ var assert = require('assert');
66var Promise = require ( './' ) ;
77
88describe ( 'Promise' , function ( ) {
9+ it ( 'should throw without new' , function ( ) {
10+ assert . throws ( function ( ) {
11+ /* eslint-disable new-cap */
12+ var promise = Promise ( function ( ) { } ) ;
13+ /* eslint-enable new-cap */
14+ assert . ok ( promise ) ;
15+ } , / F a i l e d t o c o n s t r u c t ' P r o m i s e ' : P l e a s e u s e t h e ' n e w ' o p e r a t o r , t h i s o b j e c t c o n s t r u c t o r c a n n o t b e c a l l e d a s a f u n c t i o n \. / ) ;
16+ } ) ;
17+
918 it ( 'should throw on invalid resolver type' , function ( ) {
1019 assert . throws ( function ( ) {
1120 var promise = new Promise ( 'unicorns' ) ;
1221 assert . ok ( promise ) ;
1322 } , / P r o m i s e r e s o l v e r u n i c o r n s i s n o t a f u n c t i o n / ) ;
1423 } ) ;
24+
25+ it ( 'should reject on exception in resolver' , function ( done ) {
26+ new Promise ( function ( ) {
27+ throw new Error ( 'Bang!' ) ;
28+ } )
29+ . catch ( function ( err ) {
30+ assert . equal ( err . message , 'Bang!' ) ;
31+ done ( ) ;
32+ } ) ;
33+ } ) ;
34+
35+ it ( 'should reject on exception in then' , function ( done ) {
36+ Promise . resolve ( 1 )
37+ . then ( function ( ) {
38+ throw new Error ( 'Bang!' ) ;
39+ } )
40+ . catch ( function ( err ) {
41+ assert . equal ( err . message , 'Bang!' ) ;
42+ done ( ) ;
43+ } ) ;
44+ } ) ;
45+
46+ it ( 'should return Promise from resolve value' , function ( done ) {
47+ Promise . resolve ( Promise . resolve ( 1 ) )
48+ . then ( function ( value ) {
49+ assert . equal ( value , 1 ) ;
50+ done ( ) ;
51+ } ) ;
52+ } ) ;
1553} ) ;
1654
1755describe ( 'Promise.all' , function ( ) {
56+ it ( 'should throw error on invalid argument' , function ( ) {
57+ assert . throws ( function ( ) {
58+ Promise . all ( 'unicorns' ) ;
59+ } , / Y o u m u s t p a s s a n a r r a y t o P r o m i s e .a l l ( ) ./ ) ;
60+ } ) ;
61+
1862 it ( 'should resolve empty array to empty array' , function ( done ) {
1963 Promise . all ( [ ] ) . then ( function ( value ) {
2064 assert . deepEqual ( value , [ ] ) ;
@@ -53,6 +97,12 @@ function delayedResolve() {
5397}
5498
5599describe ( 'Promise.race' , function ( ) {
100+ it ( 'should throw error on invalid argument' , function ( ) {
101+ assert . throws ( function ( ) {
102+ Promise . race ( 'unicorns' ) ;
103+ } , / Y o u m u s t p a s s a n a r r a y t o P r o m i s e .r a c e ( ) ./ ) ;
104+ } ) ;
105+
56106 it ( 'empty array should be pending' , function ( done ) {
57107 var p = Promise . race ( [ ] ) ;
58108 setTimeout ( function ( ) {
0 commit comments