title: How do I properly test a var that changes through a publisher in my viewModel in XCTestCase
body: <p>Im trying to test a simple publisher within the Combine framework and SwiftUI.  My test tests a published bool named isValid in my view model.  My view model also has a published username string, that when changes and becomes 3 characters or more isValid is assigned the value.  Here is the view model.  I am sure I am not understanding how publishers work in a test environment, timing etc...  Thanks in advance. </p>
  
  <pre><code>public class UserViewModel: ObservableObject {
    @Published var username = ""
    @Published var isValid = false
    private var disposables = Set&lt;AnyCancellable&gt;()
  
    init() {
      $username
        .receive(on: RunLoop.main)
        .removeDuplicates()
        .map { input in
          print("~~~&gt; \(input.count &gt;= 3)")
          return input.count &gt;= 3
      }
      .assign(to: \.isValid, on: self)
      .store(in: &amp;disposables)
    }
  }
  </code></pre>
  
  <p>Here is my view, not really important here</p>
  
  <pre><code>struct ContentView: View {
    @ObservedObject private var userViewModel = UserViewModel()
    var body: some View {
      TextField("Username", text: $userViewModel.username)
    }
  }
  </code></pre>
  
  <p>Here is my test file and single test that fails</p>
  
  <pre><code>class StackoverFlowQuestionTests: XCTestCase {
    var model = UserViewModel()
  
      override func setUp() {
          model = UserViewModel()
      }
  
      override func tearDown() {
      }
  
      func testIsValid() {
        model.username = "1"
        XCTAssertFalse(model.isValid)
        model.username = "1234"
        XCTAssertTrue(model.isValid) //&lt;----- THIS FAILS HERE
      }
  
  }
  </code></pre>