       callback = options
 
     beforeEach = ->
-      if template?
-        initialized = false
-        setFixtureHTML(JST["test_helpers/fixtures/#{template}"]())
-      else
-        initialized = true
+      ready = (callback) ->
+        if template?
+          addEventListener "trix-initialize", handler = ({target}) ->
+            removeEventListener("trix-initialize", handler)
+            if target.hasAttribute("autofocus")
+              target.editor.setSelectedRange(0)
+            callback(target)
+
+          setFixtureHTML(JST["test_helpers/fixtures/#{template}"]())
+        else
+          callback()
       setup?()
 
     afterEach = ->

    document.body.insertAdjacentHTML("afterbegin", """<form id="trix-container"></form>""")
    document.getElementById("trix-container")

helpers.extend
  testGroup: (name, options, callback) ->
    if callback?

helpers = Trix.TestHelpers

setFixtureHTML = (html) ->
  element = findOrCreateTrixContainer()
