func testNotConnectedEventDuringSubscribe()

in AppSyncRealTimeClientTests/Connection/AppSyncSubscriptionConnectionTests.swift [154:184]


    func testNotConnectedEventDuringSubscribe() {
        let connectionProvider = MockConnectionProviderAlwaysConnect()
        connectionProvider.isConnected = false

        let connection = AppSyncSubscriptionConnection(provider: connectionProvider)

        let connectingMessageExpectation = expectation(description: "Connecting event should be fired")
        let errorEventExpectation = expectation(description: "Error event should be fired")

        let item = connection.subscribe(
            requestString: mockRequestString,
            variables: variables
        ) { event, _ in
            switch event {
            case .connection(let status):

                if status == .connected {
                    XCTFail("Error should not be thrown")
                }
                if status == .connecting {
                    connectingMessageExpectation.fulfill()
                }
            case .data:
                XCTFail("Data event should not be published")
            case .failed:
                errorEventExpectation.fulfill()
            }
        }
        XCTAssertNotNil(item, "Subscription item should not be nil")
        wait(for: [connectingMessageExpectation, errorEventExpectation], timeout: 5, enforceOrder: true)
    }