refactor didError
This commit is contained in:
parent
dbc8b6fadc
commit
15cfba46bc
@ -100,6 +100,18 @@ class SocketSideEffectTest: XCTestCase {
|
||||
XCTAssertEqual(socket.testHandlers.count, 1)
|
||||
}
|
||||
|
||||
func testHandlesErrorPacket() {
|
||||
let expectation = expectationWithDescription("Handled error")
|
||||
socket.on("error") {data, ack in
|
||||
if let error = data[0] as? String where error == "test error" {
|
||||
expectation.fulfill()
|
||||
}
|
||||
}
|
||||
|
||||
socket.parseSocketMessage("4\"test error\"")
|
||||
waitForExpectationsWithTimeout(3, handler: nil)
|
||||
}
|
||||
|
||||
func testHandleBinaryEvent() {
|
||||
let expectation = expectationWithDescription("handled binary event")
|
||||
socket.on("test") {data, ack in
|
||||
|
||||
@ -28,17 +28,16 @@ protocol SocketClientSpec: class {
|
||||
|
||||
func didConnect()
|
||||
func didDisconnect(reason: String)
|
||||
func didError(reason: AnyObject)
|
||||
func didError(reason: String)
|
||||
func handleAck(ack: Int, data: [AnyObject])
|
||||
func handleEvent(event: String, data: [AnyObject], isInternalMessage: Bool, withAck ack: Int)
|
||||
func joinNamespace(namespace: String)
|
||||
}
|
||||
|
||||
extension SocketClientSpec {
|
||||
func didError(reason: AnyObject) {
|
||||
func didError(reason: String) {
|
||||
DefaultSocketLogger.Logger.error("%@", type: "SocketIOClient", args: reason)
|
||||
|
||||
handleEvent("error", data: reason as? [AnyObject] ?? [reason],
|
||||
isInternalMessage: true, withAck: -1)
|
||||
handleEvent("error", data: [reason], isInternalMessage: true, withAck: -1)
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ extension SocketParsable {
|
||||
case .Disconnect:
|
||||
didDisconnect("Got Disconnect")
|
||||
case .Error:
|
||||
didError(pack.data)
|
||||
handleEvent("error", data: pack.data, isInternalMessage: false, withAck: pack.id)
|
||||
default:
|
||||
DefaultSocketLogger.Logger.log("Got invalid packet: %@", type: "SocketParser", args: pack.description)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user