jeudi 31 janvier 2019

Swift - using XCTest to test function containing closure

I am fairly new to Swift and am currently trying to write a unit test (using XCTest) to test the following function:

func login(email: String, password: String)  {

    Auth.auth().signIn(withEmail: email, password: password) { (user, error) in
        if let _error = error {
            print(_error.localizedDescription)
        } else {
            self.performSegue(identifier: "loginSeg")
        }
    }
}

My research has identified that I need to use the XCTestExpectation functionality as XCTest executes synchronously by default meaning it won't wait for the closure to finish running (please correct me if I'm wrong).

Whats throwing me of is how I test the login function as it itself calls the asynchronous function Auth.auth().signIn().

Apologies if this has already been answered but I couldn't find an answer that directly addresses this issue.

Thanks

Aucun commentaire:

Enregistrer un commentaire