           atom.keymaps.handleKeyboardEvent(key)
 
           # Check for result
-          expect(editor.getBuffer().getLastLine()).toEqual ""
+          expect(editor.getBuffer().getLastLine()).toEqual('')
 
       describe "when enter is used to accept suggestions", ->
         beforeEach ->
           atom.config.set('autocomplete-plus.confirmCompletion', 'enter')
 
         it "inserts the word and moves the cursor to the end of the word", ->
-          expect(editorView.querySelector(".autocomplete-plus")).not.toExist()
+          expect(editorView.querySelector('.autocomplete-plus')).not.toExist()
 
           # Trigger an autocompletion
-          triggerAutocompletion editor
-          advanceClock completionDelay
+          triggerAutocompletion(editor)
+          advanceClock(completionDelay)
 
           autocompleteView = atom.views.getView(autocompleteManager)
           # Accept suggestion
           key = atom.keymaps.constructor.keydownEvent('enter', keyCode: 13, target: editorView)
-          atom.keymaps.handleKeyboardEvent(key);
+          atom.keymaps.handleKeyboardEvent(key)
 
           # Check for result
-          expect(editor.getBuffer().getLastLine()).toEqual "function"
+          expect(editor.getBuffer().getLastLine()).toEqual('function')
 
           # Check for cursor position
           bufferPosition = editor.getCursorBufferPosition()
-          expect(bufferPosition.row).toEqual 13
-          expect(bufferPosition.column).toEqual 8
+          expect(bufferPosition.row).toEqual(13)
+          expect(bufferPosition.column).toEqual(8)
 
         it "does not insert the word when tab completion not enabled", ->
-          expect(editorView.querySelector(".autocomplete-plus")).not.toExist()
+          expect(editorView.querySelector('.autocomplete-plus')).not.toExist()
 
           # Trigger an autocompletion
-          triggerAutocompletion editor
-          advanceClock completionDelay
+          triggerAutocompletion(editor)
+          advanceClock(completionDelay)
 
           autocompleteView = atom.views.getView(autocompleteManager)
           # Accept suggestion
           key = atom.keymaps.constructor.keydownEvent('tab', keyCode: 9, target: editorView)
-          atom.keymaps.handleKeyboardEvent(key);
+          atom.keymaps.handleKeyboardEvent(key)
 
           # Check for result
-          expect(editor.getBuffer().getLastLine()).toEqual "f "
+          expect(editor.getBuffer().getLastLine()).toEqual('f ')
 
     describe "select-previous event", ->
       it "selects the previous item in the list", ->
 
         # Trigger an autocompletion
-        triggerAutocompletion editor
-        advanceClock completionDelay
-
-        items = editorView.querySelectorAll(".autocomplete-plus li")
-        expect(items[0]).toHaveClass("selected")
-        expect(items[1]).not.toHaveClass("selected")
-        expect(items[2]).not.toHaveClass("selected")
-        expect(items[3]).not.toHaveClass("selected")
+        triggerAutocompletion(editor)
+        advanceClock(completionDelay)
+
+        items = editorView.querySelectorAll('.autocomplete-plus li')
+        expect(items[0]).toHaveClass('selected')
+        expect(items[1]).not.toHaveClass('selected')
+        expect(items[2]).not.toHaveClass('selected')
+        expect(items[3]).not.toHaveClass('selected')
 
         autocompleteView = atom.views.getView(autocompleteManager)
         # Select previous item
-        atom.commands.dispatch autocompleteView, "autocomplete-plus:select-previous"
-
-        items = editorView.querySelectorAll(".autocomplete-plus li")
-        expect(items[0]).not.toHaveClass("selected")
-        expect(items[1]).not.toHaveClass("selected")
-        expect(items[2]).not.toHaveClass("selected")
-        expect(items[3]).toHaveClass("selected")
+        atom.commands.dispatch(autocompleteView, 'autocomplete-plus:select-previous')
+
+        items = editorView.querySelectorAll('.autocomplete-plus li')
+        expect(items[0]).not.toHaveClass('selected')
+        expect(items[1]).not.toHaveClass('selected')
+        expect(items[2]).not.toHaveClass('selected')
+        expect(items[3]).toHaveClass('selected')
 
       it "closes the autocomplete when up arrow pressed when only one item displayed", ->
         # Trigger an autocompletion
-        triggerAutocompletion editor, false, 'q'
-        advanceClock completionDelay
+        triggerAutocompletion(editor, false, 'q')
+        advanceClock(completionDelay)
 
         # Accept suggestion
         key = atom.keymaps.constructor.keydownEvent('down', target: editorView)
-        atom.keymaps.handleKeyboardEvent(key);
-
-        autocomplete = editorView.querySelector(".autocomplete-plus")
+        atom.keymaps.handleKeyboardEvent(key)
+
+        autocomplete = editorView.querySelector('.autocomplete-plus')
         expect(autocomplete).not.toExist()
 
       it "does not close the autocomplete when down arrow pressed when many items", ->
         # Trigger an autocompletion
-        triggerAutocompletion editor
-        advanceClock completionDelay
+        triggerAutocompletion(editor)
+        advanceClock(completionDelay)
 
         # Accept suggestion
         key = atom.keymaps.constructor.keydownEvent('down', target: editorView)
-        atom.keymaps.handleKeyboardEvent(key);
-
-        autocomplete = editorView.querySelector(".autocomplete-plus")
+        atom.keymaps.handleKeyboardEvent(key)
+
+        autocomplete = editorView.querySelector('.autocomplete-plus')
         expect(autocomplete).toExist()
 
       it "does close the autocomplete when down arrow while up,down navigation not selected", ->
         atom.config.set('autocomplete-plus.navigateCompletions', 'ctrl-p,ctrl-n')
         # Trigger an autocompletion
-        triggerAutocompletion editor, false
-        advanceClock completionDelay
+        triggerAutocompletion(editor, false)
+        advanceClock(completionDelay)
 
         # Accept suggestion
         key = atom.keymaps.constructor.keydownEvent('down', target: editorView)
         atom.keymaps.handleKeyboardEvent(key)
 
-        autocomplete = editorView.querySelector(".autocomplete-plus")
+        autocomplete = editorView.querySelector('.autocomplete-plus')
         expect(autocomplete).not.toExist()
 
     describe "select-next event", ->
       it "selects the next item in the list", ->
         # Trigger an autocompletion
-        triggerAutocompletion editor
-        advanceClock completionDelay
-
-        items = editorView.querySelectorAll(".autocomplete-plus li")
-        expect(items[0]).toHaveClass("selected")
-        expect(items[1]).not.toHaveClass("selected")
-        expect(items[2]).not.toHaveClass("selected")
-        expect(items[3]).not.toHaveClass("selected")
+        triggerAutocompletion(editor)
+        advanceClock(completionDelay)
+
+        items = editorView.querySelectorAll('.autocomplete-plus li')
+        expect(items[0]).toHaveClass('selected')
+        expect(items[1]).not.toHaveClass('selected')
+        expect(items[2]).not.toHaveClass('selected')
+        expect(items[3]).not.toHaveClass('selected')
 
         # Select next item
         autocompleteView = atom.views.getView(autocompleteManager)
-        atom.commands.dispatch autocompleteView, "autocomplete-plus:select-next"
-
-        items = editorView.querySelectorAll(".autocomplete-plus li")
-        expect(items[0]).not.toHaveClass("selected")
-        expect(items[1]).toHaveClass("selected")
-        expect(items[2]).not.toHaveClass("selected")
-        expect(items[3]).not.toHaveClass("selected")
+        atom.commands.dispatch(autocompleteView, 'autocomplete-plus:select-next')
+
+        items = editorView.querySelectorAll('.autocomplete-plus li')
+        expect(items[0]).not.toHaveClass('selected')
+        expect(items[1]).toHaveClass('selected')
+        expect(items[2]).not.toHaveClass('selected')
+        expect(items[3]).not.toHaveClass('selected')
 
       it "closes the autocomplete when up arrow pressed when only one item displayed", ->
         # Trigger an autocompletion
-        triggerAutocompletion editor, false, 'q'
-        advanceClock completionDelay
+        triggerAutocompletion(editor, false, 'q')
+        advanceClock(completionDelay)
 
         # Accept suggestion
         key = atom.keymaps.constructor.keydownEvent('up', target: editorView)
-        atom.keymaps.handleKeyboardEvent(key);
-
-        autocomplete = editorView.querySelector(".autocomplete-plus")
+        atom.keymaps.handleKeyboardEvent(key)
+
+        autocomplete = editorView.querySelector('.autocomplete-plus')
         expect(autocomplete).not.toExist()
 
       it "does not close the autocomplete when up arrow pressed when many items", ->
         # Trigger an autocompletion
-        triggerAutocompletion editor
-        advanceClock completionDelay
+        triggerAutocompletion(editor)
+        advanceClock(completionDelay)
 
         # Accept suggestion
         key = atom.keymaps.constructor.keydownEvent('up', target: editorView)
-        atom.keymaps.handleKeyboardEvent(key);
-
-        autocomplete = editorView.querySelector(".autocomplete-plus")
+        atom.keymaps.handleKeyboardEvent(key)
+
+        autocomplete = editorView.querySelector('.autocomplete-plus')
         expect(autocomplete).toExist()
 
       it "does close the autocomplete when up arrow while up,down navigation not selected", ->
         atom.config.set('autocomplete-plus.navigateCompletions', 'ctrl-p,ctrl-n')
         # Trigger an autocompletion
-        triggerAutocompletion editor
-        advanceClock completionDelay
+        triggerAutocompletion(editor)
+        advanceClock(completionDelay)
 
         # Accept suggestion
         key = atom.keymaps.constructor.keydownEvent('up', target: editorView)
-        atom.keymaps.handleKeyboardEvent(key);
-
-        autocomplete = editorView.querySelector(".autocomplete-plus")
+        atom.keymaps.handleKeyboardEvent(key)
+
+        autocomplete = editorView.querySelector('.autocomplete-plus')
         expect(autocomplete).not.toExist()
 
     describe "when a suggestion is clicked", ->
       it "should select the item and confirm the selection", ->
         # Trigger an autocompletion
-        triggerAutocompletion editor
-        advanceClock completionDelay
+        triggerAutocompletion(editor)
+        advanceClock(completionDelay)
 
         # Get the second item
-        item = editorView.querySelectorAll(".autocomplete-plus li")[1]
+        item = editorView.querySelectorAll('.autocomplete-plus li')[1]
 
         # Click the item, expect list to be hidden and
         # text to be added
-        mouse = document.createEvent 'MouseEvents'
-        mouse.initMouseEvent 'mousedown', true, true, window
+        mouse = document.createEvent('MouseEvents')
+        mouse.initMouseEvent('mousedown', true, true, window)
         item.dispatchEvent mouse
-        mouse = document.createEvent 'MouseEvents'
-        mouse.initMouseEvent 'mouseup', true, true, window
-        item.dispatchEvent mouse
-
-        expect(editorView.querySelector(".autocomplete-plus")).not.toExist()
-        expect(editor.getBuffer().getLastLine()).toEqual item.innerText
+        mouse = document.createEvent('MouseEvents')
+        mouse.initMouseEvent('mouseup', true, true, window)
+        item.dispatchEvent(mouse)
+
+        expect(editorView.querySelector('.autocomplete-plus')).not.toExist()
+        expect(editor.getBuffer().getLastLine()).toEqual(item.innerText)
 
     describe ".cancel()", ->
       it "unbinds autocomplete event handlers for move-up and move-down", ->
-        triggerAutocompletion editor, false
+        triggerAutocompletion(editor, false)
         autocompleteManager.cancel()
-
-        atom.commands.dispatch atom.views.getView(editor), "core:move-down"
-        expect(editor.getCursorBufferPosition().row).toBe 1
-
-        atom.commands.dispatch atom.views.getView(editor) , "core:move-up"
-        expect(editor.getCursorBufferPosition().row).toBe 0
+        editorView = atom.views.getView(editor)
+        atom.commands.dispatch(editorView, 'core:move-down')
+        expect(editor.getCursorBufferPosition().row).toBe(1)
+
+        atom.commands.dispatch(editorView, 'core:move-up')
+        expect(editor.getCursorBufferPosition().row).toBe(0)
 
   describe "when a long completion exists", ->
     beforeEach ->
       runs ->
-        atom.config.set "autocomplete-plus.enableAutoActivation", true
-
-      waitsForPromise -> atom.workspace.open("samplelong.js").then (e) ->
+        atom.config.set('autocomplete-plus.enableAutoActivation', true)
+
+      waitsForPromise -> atom.workspace.open('samplelong.js').then (e) ->
         editor = e
 
       # Activate the package
-      waitsForPromise -> atom.packages.activatePackage("autocomplete-plus").then (a) ->
+      waitsForPromise -> atom.packages.activatePackage('autocomplete-plus').then (a) ->
         mainModule = a.mainModule
         autocompleteManager = mainModule.autocompleteManagers[0]
 
     it "sets the width of the view to be wide enough to contain the longest completion without scrolling", ->
       editor.moveToBottom()
       editor.insertNewline()
-      editor.insertText "t"
-      advanceClock completionDelay
+      editor.insertText('t')
+      advanceClock(completionDelay)
 
       autocompleteView = atom.views.getView(autocompleteManager)
-      expect(autocompleteView.scrollWidth).toBe autocompleteView.offsetWidth
+      expect(autocompleteView.scrollWidth).toBe(autocompleteView.offsetWidth)
 
   describe "css", ->
     [css] = []
 
     beforeEach ->
-      runs -> atom.config.set "autocomplete-plus.enableAutoActivation", true
-
-      waitsForPromise -> atom.workspace.open("css.css").then (e) ->
+      runs -> atom.config.set('autocomplete-plus.enableAutoActivation', true)
+
+      waitsForPromise -> atom.workspace.open('css.css').then (e) ->
         editor = e
 
       # Activate the package
-      waitsForPromise -> atom.packages.activatePackage("language-css").then (c) -> css = c
-
-      # Activate the package
-      waitsForPromise -> atom.packages.activatePackage("autocomplete-plus").then (a) ->
+      waitsForPromise -> atom.packages.activatePackage('language-css').then (c) -> css = c
+
+      # Activate the package
+      waitsForPromise -> atom.packages.activatePackage('autocomplete-plus').then (a) ->
         mainModule = a.mainModule
         autocompleteManager = mainModule.autocompleteManagers[0]
 


        editorView.dispatchEvent(buildIMECompositionEvent('compositionstart', target: editorView))
        editorView.dispatchEvent(buildIMECompositionEvent('compositionupdate', data: "~", target: editorView))
        advanceClock completionDelay

        expect(autocompleteManager.changeItems).not.toHaveBeenCalled()

        editorView.dispatchEvent(buildIMECompositionEvent('compositionend', target: editorView))
        editorView.firstChild.dispatchEvent(buildTextInputEvent(data: 'ã', target: editorView))

        expect(editor.lineTextForBufferRow(13)).toBe 'fã'

    describe "accepting suggestions", ->
      it "hides the suggestions list when a suggestion is confirmed", ->
        expect(editorView.querySelector(".autocomplete-plus")).not.toExist()

        # Trigger an autocompletion
        editor.moveToBottom()
        editor.moveToBeginningOfLine()
        editor.insertText("f")
        advanceClock completionDelay
        expect(editorView.querySelector(".autocomplete-plus")).toExist()

        # Accept suggestion
        autocompleteView = atom.views.getView(autocompleteManager)
        atom.commands.dispatch(autocompleteView, "autocomplete-plus:confirm")

        expect(editorView.querySelector(".autocomplete-plus")).not.toExist()

      describe "when tab is used to accept suggestions", ->
        beforeEach ->
          atom.config.set('autocomplete-plus.confirmCompletion', 'tab')

        it "inserts the word and moves the cursor to the end of the word", ->
          expect(editorView.querySelector(".autocomplete-plus")).not.toExist()

          # Trigger an autocompletion
          triggerAutocompletion editor
          advanceClock completionDelay

          autocompleteView = atom.views.getView(autocompleteManager)
          # Accept suggestion


  describe "when auto-activation is enabled", ->
    beforeEach ->
      runs -> atom.config.set('autocomplete-plus.enableAutoActivation', true)

      waitsForPromise -> atom.workspace.open('sample.js').then (e) ->
        editor = e

      # Activate the package
      waitsForPromise -> atom.packages.activatePackage('autocomplete-plus').then (a) ->
        mainModule = a.mainModule
        autocompleteManager = mainModule.autocompleteManagers[0]

