@@ -22,7 +22,7 @@ class HandlingIncomingEventsTests: XCTestCase {
22
22
func testCallbacksOnGlobalChannelShouldBeCalled( ) {
23
23
let ex = expectation ( description: " Callback should be called " )
24
24
_ = pusher. subscribe ( channelName: " my-channel " )
25
- _ = pusher. bind { ( _ : Any ? ) -> Void in
25
+ pusher. bind { event in
26
26
ex. fulfill ( )
27
27
}
28
28
@@ -41,7 +41,7 @@ class HandlingIncomingEventsTests: XCTestCase {
41
41
func testCallbacksOnRelevantChannelsShouldBeCalled( ) {
42
42
let ex = expectation ( description: " Callback should be called " )
43
43
let chan = pusher. subscribe ( " my-channel " )
44
- _ = chan. bind ( eventName: " test-event " ) { ( _ : Any ? ) -> Void in
44
+ chan. bind ( eventName: " test-event " ) { event in
45
45
ex. fulfill ( )
46
46
}
47
47
@@ -61,11 +61,13 @@ class HandlingIncomingEventsTests: XCTestCase {
61
61
let globalEx = expectation ( description: " Global callback should be called " )
62
62
let channelEx = expectation ( description: " Channel callback should be called " )
63
63
64
- let callback = { ( data: Any ? ) -> Void in globalEx. fulfill ( ) }
65
- _ = pusher. bind ( callback)
64
+ pusher. bind { event in
65
+ globalEx. fulfill ( )
66
+ }
66
67
let chan = pusher. subscribe ( " my-channel " )
67
- let callbackForChannel = { ( data: Any ? ) -> Void in channelEx. fulfill ( ) }
68
- _ = chan. bind ( eventName: " test-event " , callback: callbackForChannel)
68
+ chan. bind ( eventName: " test-event " ) { event in
69
+ channelEx. fulfill ( )
70
+ }
69
71
70
72
let jsonDict = """
71
73
{
@@ -81,12 +83,13 @@ class HandlingIncomingEventsTests: XCTestCase {
81
83
82
84
func testGlobalCallbackReturnsEventData( ) {
83
85
let ex = expectation ( description: " Callback should be called " )
84
- let callback = { ( data: Any ? ) -> Void in
85
- XCTAssertEqual ( data as! [ String : String ] , [ " event " : " test-event " , " channel " : " my-channel " , " data " : " { \" test \" : \" test string \" , \" and \" : \" another \" } " ] )
86
+ _ = pusher. subscribe ( " my-channel " )
87
+ pusher. bind { event in
88
+ XCTAssertEqual ( event. channelName, " my-channel " )
89
+ XCTAssertEqual ( event. eventName, " test-event " )
90
+ XCTAssertEqual ( event. dataToJSONObject ( ) as! [ String : String ] , [ " test " : " test string " , " and " : " another " ] )
86
91
ex. fulfill ( )
87
92
}
88
- _ = pusher. subscribe ( " my-channel " )
89
- _ = pusher. bind ( callback)
90
93
91
94
let jsonDict = """
92
95
{
@@ -108,12 +111,13 @@ class HandlingIncomingEventsTests: XCTestCase {
108
111
*/
109
112
func testGlobalCallbackReturnsEventDataWithoutChannelName( ) {
110
113
let ex = expectation ( description: " Callback should be called " )
111
- let callback = { ( data: Any ? ) -> Void in
112
- XCTAssertEqual ( data as! [ String : String ] , [ " event " : " test-event " , " data " : " { \" test \" : \" test string \" , \" and \" : \" another \" } " ] )
114
+ _ = pusher. subscribe ( " my-channel " )
115
+ pusher. bind { event in
116
+ XCTAssertNil ( event. channelName)
117
+ XCTAssertEqual ( event. eventName, " test-event " )
118
+ XCTAssertEqual ( event. dataToJSONObject ( ) as! [ String : String ] , [ " test " : " test string " , " and " : " another " ] )
113
119
ex. fulfill ( )
114
120
}
115
- _ = pusher. subscribe ( " my-channel " )
116
- _ = pusher. bind ( callback)
117
121
118
122
let jsonDict = """
119
123
{
@@ -162,14 +166,13 @@ class HandlingIncomingEventsTests: XCTestCase {
162
166
func testReturningAJSONObjectToCallbacksIfTheStringCanBeParsed( ) {
163
167
let ex = expectation ( description: " Callback should be called " )
164
168
165
- let callback = { ( data: Any ? ) -> Void in
166
- XCTAssertEqual ( data as! [ String : String ] , [ " test " : " test string " , " and " : " another " ] )
169
+ let chan = pusher. subscribe ( " my-channel " )
170
+ chan. bind ( eventName: " test-event " ) { event in
171
+ event. dataToJSONObject ( ) as! [ String : String ]
172
+ XCTAssertEqual ( event. dataToJSONObject ( ) as! [ String : String ] , [ " test " : " test string " , " and " : " another " ] )
167
173
ex. fulfill ( )
168
174
}
169
175
170
- let chan = pusher. subscribe ( " my-channel " )
171
- _ = chan. bind ( eventName: " test-event " , callback: callback)
172
-
173
176
let jsonDict = """
174
177
{
175
178
" event " : " test-event " ,
@@ -185,14 +188,12 @@ class HandlingIncomingEventsTests: XCTestCase {
185
188
func testReturningAJSONStringToCallbacksIfTheStringCannotBeParsed( ) {
186
189
let ex = expectation ( description: " Callback should be called " )
187
190
188
- let callback = { ( data: Any ? ) -> Void in
189
- XCTAssertEqual ( data as? String , " test " )
191
+ let chan = pusher. subscribe ( " my-channel " )
192
+ chan. bind ( eventName: " test-event " ) { event in
193
+ XCTAssertEqual ( event. data, " test " )
190
194
ex. fulfill ( )
191
195
}
192
196
193
- let chan = pusher. subscribe ( " my-channel " )
194
- _ = chan. bind ( eventName: " test-event " , callback: callback)
195
-
196
197
let jsonDict = """
197
198
{
198
199
" event " : " test-event " ,
@@ -212,12 +213,11 @@ class HandlingIncomingEventsTests: XCTestCase {
212
213
pusher = Pusher ( key: key, options: options)
213
214
socket. delegate = pusher. connection
214
215
pusher. connection. socket = socket
215
- let callback = { ( data: Any ? ) -> Void in
216
- XCTAssertEqual ( data as? String , " { \" test \" : \" test string \" , \" and \" : \" another \" } " )
216
+ let chan = pusher. subscribe ( " my-channel " )
217
+ chan. bind ( eventName: " test-event " ) { event in
218
+ XCTAssertEqual ( event. data, " { \" test \" : \" test string \" , \" and \" : \" another \" } " )
217
219
ex. fulfill ( )
218
220
}
219
- let chan = pusher. subscribe ( " my-channel " )
220
- _ = chan. bind ( eventName: " test-event " , callback: callback)
221
221
222
222
let jsonDict = """
223
223
{
@@ -257,7 +257,8 @@ class HandlingIncomingEventsTests: XCTestCase {
257
257
func testEventObjectReturnedToChannelCallback( ) {
258
258
let ex = expectation ( description: " Callback should be called " )
259
259
260
- let callback = { ( event: PusherEvent ) -> Void in
260
+ let chan = pusher. subscribe ( " my-channel " )
261
+ chan. bind ( eventName: " test-event " ) { event in
261
262
XCTAssertEqual ( event. eventName, " test-event " )
262
263
XCTAssertEqual ( event. channelName!, " my-channel " )
263
264
XCTAssertEqual ( event. data!, " { \" test \" : \" test string \" , \" and \" : \" another \" } " )
@@ -272,8 +273,6 @@ class HandlingIncomingEventsTests: XCTestCase {
272
273
273
274
ex. fulfill ( )
274
275
}
275
- let chan = pusher. subscribe ( " my-channel " )
276
- _ = chan. bind ( eventName: " test-event " , eventCallback: callback)
277
276
278
277
let jsonDict = """
279
278
{
@@ -290,7 +289,8 @@ class HandlingIncomingEventsTests: XCTestCase {
290
289
func testEventObjectReturnedToGlobalCallback( ) {
291
290
let ex = expectation ( description: " Callback should be called " )
292
291
293
- let callback = { ( event: PusherEvent ) -> Void in
292
+ _ = pusher. subscribe ( " my-channel " )
293
+ pusher. bind { event in
294
294
XCTAssertEqual ( event. eventName, " test-event " )
295
295
XCTAssertEqual ( event. channelName!, " my-channel " )
296
296
XCTAssertEqual ( event. data!, " { \" test \" : \" test string \" , \" and \" : \" another \" } " )
@@ -305,8 +305,6 @@ class HandlingIncomingEventsTests: XCTestCase {
305
305
306
306
ex. fulfill ( )
307
307
}
308
- _ = pusher. subscribe ( " my-channel " )
309
- _ = pusher. bind ( eventCallback: callback)
310
308
311
309
XCTAssertNil ( socket. eventGivenToCallback)
312
310
let jsonDict = """
0 commit comments