title: After moving from `jquery_ujs` to `rails-ujs`, why are jquery objects not initialized in tests?
body: <p>After migrating from <code>jquery_ujs</code> to <code>rails-ujs</code>, certain JS tests are failing and proving very difficult to debug. </p>
  
  <p>The problem appears to be that Jquery objects are only initialized for the first test in a sequence. Everything works fine in my development environment. </p>
  
  <p>After upgrading to Rails 5.1 everything was working with <code>jquery_ujs</code>. I then made only one change in <code>application.js</code>.</p>
  
  <pre><code>#added this
  //= require rails-ujs
  # removed this
  //= require jquery_ujs
  </code></pre>
  
  <p>Here's an example. Two almost identical system tests for interaction with a select2 field. </p>
  
  <pre><code>it "selects recognized search strings", :js do
    expect(MyRemoteSelectBuilder).to receive(:search_query).
      with("recognized_string").once.
      and_return(
        [
          id:   1,
          name: "Recognized Name"
        ]
      )
  
    visit new_my_object_path 
    # triggers the select2 
    is_expected.to have_selector('.select2-container', visible: false)
    first('.select2-container', minimum: 1).click
    # do some more stuff
  end
  it "does not select unrecognized search strings", :js do
    expect(MyRemoteSelectBuilder).to receive(:search_query).
      with("unrecognized_string").once.
      and_return(
        [ ]
      )
  
    visit new_my_object_path 
    # triggers the select2 
    is_expected.to have_selector('.select2-container', visible: false)
    first('.select2-container', minimum: 1).click
    # do some more stuff
  end
  </code></pre>
  
  <p>When run together, one of these tests will fail with </p>
  
  <pre><code>expected to find css ".select2-container" but there were no matches  
  </code></pre>
  
  <p>If I focus and run only one or other of these tests, they will pass. </p>
  
  <p>I considered whether this might be a turbolinks issue (I don't think it is as the tests pass sometimes). Nonetheless I have tried various ways to initialize Select2 with Turbolinks but without success. </p>
  
  <pre><code>(($) -&gt;
    $(document).on 'turbolinks:load', -&gt;
      InititializeSelect2.init()
      return
    return
  ) jQuery
  
  # or 
  $ -&gt;  
    InititializeSelect2.init()
  # etc
  </code></pre>
  
  <p>Is there a fundamental difference between <code>rails-ujs</code> or <code>jquery_ujs</code> that could affect jquery initialization between tests? Have I overlooked some configuration? What would be logical steps to debug this issue? </p>