     QUnit.test name, (assert) ->
       doneAsync = assert.async()
 
-      done = (expectedDocumentValue) ->
-        if expectedDocumentValue
-          assert.equal getDocument().toString(), expectedDocumentValue
-        doneAsync()
-
-      ready ->
-        if getEditorElement()?.hasAttribute("autofocus")
-          getEditorController().setLocationRange(index: 0, offset: 0)
+      ready (element) ->
+        done = (expectedDocumentValue) ->
+          if element?
+            if expectedDocumentValue
+              assert.equal element.editor.getDocument().toString(), expectedDocumentValue
+            requestAnimationFrame(doneAsync)
+          else
+            doneAsync()
 
         if callback.length is 0
           callback()

    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()
