Skip to content

Commit 5c0bbde

Browse files
committed
add test for transport open calling connect
1 parent cd24543 commit 5c0bbde

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

SocketIO-MacTests/SocketSideEffectTest.swift

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ class SocketSideEffectTest: XCTestCase {
252252
let expect = expectation(description: "The client should call the timeout function")
253253

254254
socket.setTestStatus(.notConnected)
255+
socket.nsp = "/someNamespace"
255256
socket.engine = TestEngine(client: socket, url: socket.socketURL, options: nil)
256257

257258
socket.connect(timeoutAfter: 0.5, withHandler: {
@@ -283,6 +284,23 @@ class SocketSideEffectTest: XCTestCase {
283284
waitForExpectations(timeout: 2)
284285
}
285286

287+
func testClientCallsConnectOnEngineOpen() {
288+
let expect = expectation(description: "The client call the connect handler")
289+
290+
socket.setTestStatus(.notConnected)
291+
socket.engine = TestEngine(client: socket, url: socket.socketURL, options: nil)
292+
293+
socket.on(clientEvent: .connect) {data, ack in
294+
expect.fulfill()
295+
}
296+
297+
socket.connect(timeoutAfter: 0.5, withHandler: {
298+
XCTFail("Should not call timeout handler if status is connected")
299+
})
300+
301+
waitForExpectations(timeout: 2)
302+
}
303+
286304
func testConnectIsCalledWithNamespace() {
287305
let expect = expectation(description: "The client should not call the timeout function")
288306
let nspString = "/swift"
@@ -399,7 +417,7 @@ struct ThrowingData : SocketData {
399417
}
400418

401419
class TestEngine : SocketEngineSpec {
402-
var client: SocketEngineClient? = nil
420+
weak var client: SocketEngineClient?
403421
private(set) var closed = false
404422
private(set) var connected = false
405423
var connectParams: [String: Any]? = nil
@@ -418,9 +436,14 @@ class TestEngine : SocketEngineSpec {
418436
private(set) var websocket = false
419437
private(set) var ws: WebSocket? = nil
420438

421-
required init(client: SocketEngineClient, url: URL, options: NSDictionary?) { }
439+
required init(client: SocketEngineClient, url: URL, options: NSDictionary?) {
440+
self.client = client
441+
}
442+
443+
func connect() {
444+
client?.engineDidOpen(reason: "Connect")
445+
}
422446

423-
func connect() { }
424447
func didError(reason: String) { }
425448
func disconnect(reason: String) { }
426449
func doFastUpgrade() { }

0 commit comments

Comments
 (0)