Skip to content

Commit 141b0ce

Browse files
committed
Add test for namespace in connect
1 parent 206e1ee commit 141b0ce

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

SocketIO-MacTests/SocketSideEffectTest.swift

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,31 +226,61 @@ class SocketSideEffectTest: XCTestCase {
226226

227227
socket.setTestStatus(.notConnected)
228228

229-
socket.connect(timeoutAfter: 1, withHandler: {
229+
socket.connect(timeoutAfter: 0.2, withHandler: {
230230
expect.fulfill()
231231
})
232232

233-
waitForExpectations(timeout: 2)
233+
waitForExpectations(timeout: 0.4)
234234
}
235235

236236
func testConnectDoesNotTimeOutIfConnected() {
237237
let expect = expectation(description: "The client should not call the timeout function")
238238

239239
socket.setTestStatus(.notConnected)
240240

241-
socket.connect(timeoutAfter: 1, withHandler: {
241+
socket.connect(timeoutAfter: 0.3, withHandler: {
242242
XCTFail("Should not call timeout handler if status is connected")
243243
})
244244

245-
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.2) {
245+
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) {
246246
// Fake connecting
247247
self.socket.setTestStatus(.connected)
248248
}
249249

250-
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1.1) {
250+
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.5) {
251+
expect.fulfill()
252+
}
253+
254+
waitForExpectations(timeout: 2)
255+
}
256+
257+
func testConnectIsCalledWithNamepsace() {
258+
let expect = expectation(description: "The client should not call the timeout function")
259+
let nspString = "/swift"
260+
261+
socket.setTestStatus(.notConnected)
262+
263+
socket.on(clientEvent: .connect) {data, ack in
264+
guard let nsp = data[0] as? String else {
265+
XCTFail("Connect should be called with a namespace")
266+
267+
return
268+
}
269+
270+
XCTAssertEqual(nspString, nsp, "It should connect with the correct namespace")
271+
251272
expect.fulfill()
252273
}
253274

275+
socket.connect(timeoutAfter: 0.3, withHandler: {
276+
XCTFail("Should not call timeout handler if status is connected")
277+
})
278+
279+
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) {
280+
// Fake connecting
281+
self.socket.parseEngineMessage("0/swift")
282+
}
283+
254284
waitForExpectations(timeout: 2)
255285
}
256286

0 commit comments

Comments
 (0)