Skip to content

Commit 0aabff8

Browse files
committed
Fixed testcase bugs
1 parent 3d09ef6 commit 0aabff8

3 files changed

Lines changed: 16 additions & 10 deletions

File tree

Auth0UniversalComponents/Auth0UniversalComponentsSDKInitializer.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,13 @@ public actor Auth0UniversalComponentsSDKInitializer {
153153
tokenProvider: tokenProvider)
154154
}
155155

156-
/// Reset the SDK to an uninitialized state.
156+
/// Reset the SDK telemetry state.
157157
///
158-
/// This is primarily used for testing purposes to clear the singleton instance.
158+
/// This is primarily used for testing purposes. It resets the TelemetryManager
159+
/// but does not nil out the shared instance to avoid race conditions in parallel tests.
160+
/// The subsequent `initialize()` call will overwrite the instance completely.
159161
static func reset() {
160-
_shared = nil
162+
TelemetryManager.shared = TelemetryManager(configuration: .enabled)
161163
}
162164
}
163165

Auth0UniversalComponentsTests/Mocks/MockURLProtocol.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import Foundation
22

33
final class MockURLProtocol: URLProtocol {
4-
static var requestHandler: ((URLRequest) throws -> (HTTPURLResponse, Data?))?
4+
nonisolated(unsafe) static var requestHandler: ((URLRequest) throws -> (HTTPURLResponse, Data?))?
5+
6+
private var capturedHandler: ((URLRequest) throws -> (HTTPURLResponse, Data?))?
7+
8+
override init(request: URLRequest, cachedResponse: CachedURLResponse?, client: (any URLProtocolClient)?) {
9+
capturedHandler = Self.requestHandler
10+
super.init(request: request, cachedResponse: cachedResponse, client: client)
11+
}
512

613
override static func canInit(with request: URLRequest) -> Bool {
714
return true
@@ -12,8 +19,9 @@ final class MockURLProtocol: URLProtocol {
1219
}
1320

1421
override func startLoading() {
15-
guard let handler = MockURLProtocol.requestHandler else {
16-
fatalError("MockURLProtocol requires a requestHandler.")
22+
guard let handler = capturedHandler else {
23+
client?.urlProtocol(self, didFailWithError: URLError(.unknown))
24+
return
1725
}
1826

1927
do {

Auth0UniversalComponentsTests/TOTPPushEnrollment/OTPViewModelTests.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,6 @@ struct OTPViewModelTests {
102102
return data
103103
}
104104

105-
init() async throws {
106-
Auth0UniversalComponentsSDKInitializer.reset()
107-
}
108-
109105
@Test func testInit_initialState() async {
110106
let mockTokenProvider = MockTokenProvider()
111107

0 commit comments

Comments
 (0)