diff --git a/RxScreenProtectKitTests/RxScreenProtectKitTests.swift b/RxScreenProtectKitTests/RxScreenProtectKitTests.swift index ee2d326..ac480c7 100644 --- a/RxScreenProtectKitTests/RxScreenProtectKitTests.swift +++ b/RxScreenProtectKitTests/RxScreenProtectKitTests.swift @@ -187,12 +187,17 @@ final class RxScreenProtectKitTests: XCTestCase { } func testSPLabel() { + let changeTextExpectation: XCTestExpectation? = self.expectation(description: "Change Text") let label = SPLabel() label.layoutSubviews() XCTAssertEqual(label.text, nil) label.text = "original" label.protectText = "protect" - XCTAssertEqual(label.text, "original") + DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { + XCTAssertEqual(label.text, "original") + changeTextExpectation?.fulfill() + } + self.waitForExpectations(timeout: 1, handler: nil) } func testPixelBoxSize() { diff --git a/Source/SPLabel.swift b/Source/SPLabel.swift index 676209d..1f0ac51 100644 --- a/Source/SPLabel.swift +++ b/Source/SPLabel.swift @@ -14,16 +14,18 @@ public final class SPLabel: UILabel { private var original: String? /// Specify the character string to be replaced during recording. /// If nothing is specified, `nil` is assigned to `text` when a recording is detected. - public var protectText: String? + public var protectText: String? { + didSet { + load.onNext(()) + } + } /// The current text that is displayed by the label. /// Please note that when recording, a different string will be returned from the original string. override public var text: String? { set { super.text = newValue original = newValue - if newValue != nil { - load.onNext(()) - } + load.onNext(()) } get { return super.text