@@ -23,8 +23,10 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.2", () => {
23
23
var un = new Unmarshaller ( ) ;
24
24
25
25
// act and assert
26
- expect ( un . unmarshall . bind ( un , payload ) )
27
- . to . throw ( "payload is null or undefined" ) ;
26
+ return un . unmarshall ( payload )
27
+ . then ( actual => { throw { message : "failed" } } )
28
+ . catch ( err =>
29
+ expect ( err . message ) . to . equal ( "payload is null or undefined" ) ) ;
28
30
} ) ;
29
31
30
32
it ( "Throw error when headers is null" , ( ) => {
@@ -34,8 +36,10 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.2", () => {
34
36
var un = new Unmarshaller ( ) ;
35
37
36
38
// act and assert
37
- expect ( un . unmarshall . bind ( un , payload , headers ) )
38
- . to . throw ( "headers is null or undefined" ) ;
39
+ return un . unmarshall ( payload , headers )
40
+ . then ( actual => { throw { message : "failed" } } )
41
+ . catch ( err =>
42
+ expect ( err . message ) . to . equal ( "headers is null or undefined" ) ) ;
39
43
} ) ;
40
44
41
45
it ( "Throw error when there is no content-type header" , ( ) => {
@@ -45,8 +49,10 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.2", () => {
45
49
var un = new Unmarshaller ( ) ;
46
50
47
51
// act and assert
48
- expect ( un . unmarshall . bind ( un , payload , headers ) )
49
- . to . throw ( "content-type header not found" ) ;
52
+ un . unmarshall ( payload , headers )
53
+ . then ( actual => { throw { message : "failed" } } )
54
+ . catch ( err =>
55
+ expect ( err . message ) . to . equal ( "content-type header not found" ) ) ;
50
56
} ) ;
51
57
52
58
it ( "Throw error when content-type is not allowed" , ( ) => {
@@ -58,8 +64,10 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.2", () => {
58
64
var un = new Unmarshaller ( ) ;
59
65
60
66
// act and assert
61
- expect ( un . unmarshall . bind ( un , payload , headers ) )
62
- . to . throw ( "content type not allowed" ) ;
67
+ un . unmarshall ( payload , headers )
68
+ . then ( actual => { throw { message : "failed" } } )
69
+ . catch ( err =>
70
+ expect ( err . message ) . to . equal ( "content type not allowed" ) ) ;
63
71
} ) ;
64
72
65
73
describe ( "Structured" , ( ) => {
@@ -72,8 +80,10 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.2", () => {
72
80
var un = new Unmarshaller ( ) ;
73
81
74
82
// act and assert
75
- expect ( un . unmarshall . bind ( un , payload , headers ) )
76
- . to . throw ( "structured+type not allowed" ) ;
83
+ un . unmarshall ( payload , headers )
84
+ . then ( actual => { throw { message : "failed" } } )
85
+ . catch ( err =>
86
+ expect ( err . message ) . to . equal ( "structured+type not allowed" ) ) ;
77
87
} ) ;
78
88
79
89
it ( "Throw error when the event does not follow the spec 0.2" , ( ) => {
@@ -95,8 +105,10 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.2", () => {
95
105
var un = new Unmarshaller ( ) ;
96
106
97
107
// act and assert
98
- expect ( un . unmarshall . bind ( un , payload , headers ) )
99
- . to . throw ( "invalid payload" ) ;
108
+ un . unmarshall ( payload , headers )
109
+ . then ( actual => { throw { message : "failed" } } )
110
+ . catch ( err =>
111
+ expect ( err . message ) . to . equal ( "invalid payload" ) ) ;
100
112
} ) ;
101
113
102
114
it ( "Should accept event that follow the spec 0.2" , ( ) => {
@@ -117,12 +129,11 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.2", () => {
117
129
118
130
var un = new Unmarshaller ( ) ;
119
131
120
- // act
121
- var actual = un . unmarshall ( payload , headers ) ;
132
+ // act and assert
133
+ un . unmarshall ( payload , headers )
134
+ . then ( actual =>
135
+ expect ( actual ) . to . be . an ( "object" ) ) ;
122
136
123
- // assert
124
- expect ( actual )
125
- . to . be . an ( "object" ) ;
126
137
} ) ;
127
138
} ) ;
128
139
@@ -145,8 +156,11 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.2", () => {
145
156
var un = new Unmarshaller ( ) ;
146
157
147
158
// act and assert
148
- expect ( un . unmarshall . bind ( un , payload , attributes ) )
149
- . to . throw ( "content type not allowed" ) ;
159
+ un . unmarshall ( payload , attributes )
160
+ . then ( actual => { throw { message : "failed" } } )
161
+ . catch ( err =>
162
+ expect ( err . message ) . to . equal ( "content type not allowed" ) ) ;
163
+
150
164
} ) ;
151
165
152
166
it ( "Throw error when the event does not follow the spec 0.2" , ( ) => {
@@ -167,8 +181,10 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.2", () => {
167
181
var un = new Unmarshaller ( ) ;
168
182
169
183
// act and assert
170
- expect ( un . unmarshall . bind ( un , payload , attributes ) )
171
- . to . throw ( ) ;
184
+ un . unmarshall ( payload , attributes )
185
+ . then ( actual => { throw { message : "failed" } } )
186
+ . catch ( err =>
187
+ expect ( err . message ) . to . not . empty ( ) ) ;
172
188
} ) ;
173
189
174
190
it ( "No error when all attributes are in place" , ( ) => {
@@ -188,12 +204,9 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.2", () => {
188
204
189
205
var un = new Unmarshaller ( ) ;
190
206
191
- // act
192
- var actual = un . unmarshall ( payload , attributes ) ;
193
-
194
- // assert
195
- expect ( actual )
196
- . to . be . an ( "object" ) ;
207
+ // act and assert
208
+ un . unmarshall ( payload , attributes )
209
+ . then ( actual => expect ( actual ) . to . be . an ( "object" ) ) ;
197
210
198
211
} ) ;
199
212
} ) ;
0 commit comments