diff --git a/Tests/WebUITests/WeakReference.swift b/Tests/WebUITests/WeakReference.swift new file mode 100644 index 0000000..455ec9a --- /dev/null +++ b/Tests/WebUITests/WeakReference.swift @@ -0,0 +1,8 @@ +final class WeakReference where T : AnyObject { + weak var value: T? + + func bypass(_ value: T) -> T { + self.value = value + return value + } +} diff --git a/Tests/WebUITests/WebViewTests.swift b/Tests/WebUITests/WebViewTests.swift index 1e37156..7db47f8 100644 --- a/Tests/WebUITests/WebViewTests.swift +++ b/Tests/WebUITests/WebViewTests.swift @@ -2,6 +2,14 @@ import XCTest final class WebViewTests: XCTestCase { + @MainActor + func test_configuration_is_weakly_referenced() { + var configuration = WebViewConfigurationMock?.some(.init()) + let sut = WebView(configuration: configuration) + configuration = nil + XCTAssertNil(sut.configuration) + } + @MainActor func test_applyModifiers_uiDelegate() { let uiDelegateMock = UIDelegateMock() @@ -11,6 +19,16 @@ final class WebViewTests: XCTestCase { XCTAssertTrue(uiDelegateMock === webViewMock.uiDelegate) } + @MainActor + func test_uiDelegate_is_weakly_referenced() { + let actual = WeakReference() + let sut = WebView().uiDelegate(actual.bypass(.init())) + var webViewMock = EnhancedWKWebViewMock?.some(.init()) + sut.applyModifiers(to: webViewMock!) + webViewMock = nil + XCTAssertNil(actual.value) + } + @MainActor func test_applyModifiers_navigationDelegate() { let navigationDelegateMock = NavigationDelegateMock() @@ -20,6 +38,16 @@ final class WebViewTests: XCTestCase { XCTAssertTrue(navigationDelegateMock === webViewMock.navigationDelegateProxy.delegate) } + @MainActor + func test_navigationDelegate_is_weakly_referenced() { + let actual = WeakReference() + let sut = WebView().navigationDelegate(actual.bypass(.init())) + var webViewMock = EnhancedWKWebViewMock?.some(.init()) + sut.applyModifiers(to: webViewMock!) + webViewMock = nil + XCTAssertNil(actual.value) + } + @MainActor func test_applyModifiers_isInspectable() { let sut = WebView().allowsInspectable(true)