@@ -25,11 +25,70 @@ describe('extensions', function () {
25
25
assert ( promise === Promise . from ( promise ) )
26
26
} )
27
27
} )
28
+ describe ( 'if passed a thenable' , function ( ) {
29
+ describe ( 'using then' , function ( ) {
30
+ it ( 'assimilates it' , function ( done ) {
31
+ var i = 2
32
+ var promise = Promise . from ( thenable )
33
+ var promiseRejected = Promise . from ( thenableRejected )
34
+ assert ( promise instanceof Promise )
35
+ assert ( promiseRejected instanceof Promise )
36
+ promise . then ( function ( res ) {
37
+ assert ( res === sentinel )
38
+ if ( 0 === -- i ) done ( )
39
+ } )
40
+ . then ( null , done )
41
+ promiseRejected . then ( null , function ( err ) {
42
+ assert ( err === sentinel )
43
+ if ( 0 === -- i ) done ( )
44
+ } )
45
+ . then ( null , done )
46
+ } )
47
+ } )
48
+ describe ( 'using catch' , function ( ) {
49
+ it ( 'assimilates it' , function ( done ) {
50
+ var i = 2
51
+ var promise = Promise . from ( thenable )
52
+ var promiseRejected = Promise . from ( thenableRejected )
53
+ assert ( promise instanceof Promise )
54
+ assert ( promiseRejected instanceof Promise )
55
+ promise . then ( function ( res ) {
56
+ assert ( res === sentinel )
57
+ if ( 0 === -- i ) done ( )
58
+ } )
59
+ . catch ( done )
60
+ promiseRejected . catch ( function ( err ) {
61
+ assert ( err === sentinel )
62
+ if ( 0 === -- i ) done ( )
63
+ } )
64
+ . catch ( done )
65
+ } )
66
+ } )
67
+ } )
68
+ describe ( 'if passed a value' , function ( ) {
69
+ it ( 'wraps it in a promise' , function ( done ) {
70
+ var promise = Promise . from ( sentinel )
71
+ . then ( function ( res ) {
72
+ assert ( res === sentinel )
73
+ done ( )
74
+ } )
75
+ assert ( promise instanceof Promise )
76
+ assert ( Promise . from ( sentinel ) instanceof Promise )
77
+ assert ( Promise . from ( sentinel ) . constructor === Promise )
78
+ } )
79
+ } )
80
+ } )
81
+ describe ( 'Promise.cast' , function ( ) {
82
+ describe ( 'if passed a true promise' , function ( ) {
83
+ it ( 'returns it directly' , function ( ) {
84
+ assert ( promise === Promise . cast ( promise ) )
85
+ } )
86
+ } )
28
87
describe ( 'if passed a thenable' , function ( ) {
29
88
it ( 'assimilates it' , function ( done ) {
30
89
var i = 2
31
- var promise = Promise . from ( thenable )
32
- var promiseRejected = Promise . from ( thenableRejected )
90
+ var promise = Promise . cast ( thenable )
91
+ var promiseRejected = Promise . cast ( thenableRejected )
33
92
assert ( promise instanceof Promise )
34
93
assert ( promiseRejected instanceof Promise )
35
94
promise . then ( function ( res ) {
@@ -46,14 +105,14 @@ describe('extensions', function () {
46
105
} )
47
106
describe ( 'if passed a value' , function ( ) {
48
107
it ( 'wraps it in a promise' , function ( done ) {
49
- var promise = Promise . from ( sentinel )
108
+ var promise = Promise . cast ( sentinel )
50
109
. then ( function ( res ) {
51
110
assert ( res === sentinel )
52
111
done ( )
53
112
} )
54
113
assert ( promise instanceof Promise )
55
- assert ( Promise . from ( sentinel ) instanceof Promise )
56
- assert ( Promise . from ( sentinel ) . constructor === Promise )
114
+ assert ( Promise . cast ( sentinel ) instanceof Promise )
115
+ assert ( Promise . cast ( sentinel ) . constructor === Promise )
57
116
} )
58
117
} )
59
118
} )
0 commit comments