@@ -25,22 +25,31 @@ class EmailPasswordTests: TestsBase {
25
25
/// ** The testing email address for testSignInExistingUserWithEmailAndPassword. */
26
26
let kExistingEmailToSignIn = " [email protected] "
27
27
28
- func testCreateAccountWithEmailAndPassword( ) {
28
+ func testCreateAccountWithEmailAndPassword( ) async throws {
29
29
let auth = Auth . auth ( )
30
+ // Ensure the account that will be created does not already exist.
31
+ let result = try ? await auth. signIn ( withEmail: kNewEmailToCreateUser, password: " password " )
32
+ try ? await result? . user. delete ( )
33
+
30
34
let expectation = self . expectation ( description: " Created account with email and password. " )
31
35
auth. createUser ( withEmail: kNewEmailToCreateUser, password: " password " ) { result, error in
32
36
if let error {
33
37
print ( " createUserWithEmail has error: \( error) " )
34
38
}
35
39
expectation. fulfill ( )
36
40
}
37
- waitForExpectations ( timeout: TestsBase . kExpectationsTimeout)
41
+ await fulfillment ( of: [ expectation] , timeout: TestsBase . kExpectationsTimeout)
42
+
38
43
XCTAssertEqual ( auth. currentUser? . email, kNewEmailToCreateUser, " Expected email doesn't match " )
39
- deleteCurrentUser ( )
44
+ try ? await deleteCurrentUserAsync ( )
40
45
}
41
46
42
47
func testCreateAccountWithEmailAndPasswordAsync( ) async throws {
43
48
let auth = Auth . auth ( )
49
+ // Ensure the account that will be created does not already exist.
50
+ let result = try ? await auth. signIn ( withEmail: kNewEmailToCreateUser, password: " password " )
51
+ try ? await result? . user. delete ( )
52
+
44
53
try await auth. createUser ( withEmail: kNewEmailToCreateUser, password: " password " )
45
54
XCTAssertEqual ( auth. currentUser? . email, kNewEmailToCreateUser, " Expected email doesn't match " )
46
55
try await deleteCurrentUserAsync ( )
0 commit comments