           expect(editor).not.toHaveClass 'command-mode'
           expect(editor).toHaveClass 'insert-mode'
 
-          editor.trigger keydownEvent('escape')
+          keydown('escape', element: editor[0])
 
           editor.setText("one two three four")
           editor.setCursorScreenPosition([0,0])


  describe "insert-mode", ->
    beforeEach ->
      editor.trigger keydownEvent('i')

    it "allows the cursor to reach the end of the line", ->
      editor.setText("012345\n\nabcdef")

          expect(editor).not.toHaveClass 'command-mode'
          expect(editor).toHaveClass 'insert-mode'

          keydown('escape', element: editor[0])

          editor.setText("one two three four")
          editor.setCursorScreenPosition([0,11])
