From 141b0ce6bcf1ba348764687d80ee70b41098ab88 Mon Sep 17 00:00:00 2001 From: Erik Date: Tue, 4 Jul 2017 08:37:18 -0400 Subject: [PATCH] Add test for namespace in connect --- SocketIO-MacTests/SocketSideEffectTest.swift | 40 +++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/SocketIO-MacTests/SocketSideEffectTest.swift b/SocketIO-MacTests/SocketSideEffectTest.swift index d1edcb4..2569260 100644 --- a/SocketIO-MacTests/SocketSideEffectTest.swift +++ b/SocketIO-MacTests/SocketSideEffectTest.swift @@ -226,11 +226,11 @@ class SocketSideEffectTest: XCTestCase { socket.setTestStatus(.notConnected) - socket.connect(timeoutAfter: 1, withHandler: { + socket.connect(timeoutAfter: 0.2, withHandler: { expect.fulfill() }) - waitForExpectations(timeout: 2) + waitForExpectations(timeout: 0.4) } func testConnectDoesNotTimeOutIfConnected() { @@ -238,22 +238,52 @@ class SocketSideEffectTest: XCTestCase { socket.setTestStatus(.notConnected) - socket.connect(timeoutAfter: 1, withHandler: { + socket.connect(timeoutAfter: 0.3, withHandler: { XCTFail("Should not call timeout handler if status is connected") }) - DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.2) { + DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) { // Fake connecting self.socket.setTestStatus(.connected) } - DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1.1) { + DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.5) { expect.fulfill() } waitForExpectations(timeout: 2) } + func testConnectIsCalledWithNamepsace() { + let expect = expectation(description: "The client should not call the timeout function") + let nspString = "/swift" + + socket.setTestStatus(.notConnected) + + socket.on(clientEvent: .connect) {data, ack in + guard let nsp = data[0] as? String else { + XCTFail("Connect should be called with a namespace") + + return + } + + XCTAssertEqual(nspString, nsp, "It should connect with the correct namespace") + + expect.fulfill() + } + + socket.connect(timeoutAfter: 0.3, withHandler: { + XCTFail("Should not call timeout handler if status is connected") + }) + + DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) { + // Fake connecting + self.socket.parseEngineMessage("0/swift") + } + + waitForExpectations(timeout: 2) + } + func testErrorInCustomSocketDataCallsErrorHandler() { let expect = expectation(description: "The client should call the error handler for emit errors because of " + "custom data")