   classListContains = (klass) ->
     expect editorElement.classList.contains(klass)
 
-  describe "the 'iw' text object", ->
-    beforeEach ->
-      text "12345 abcde ABCDE"
-      cursor [0, 9]
-
-    it "applies operators inside the current word in operator-pending mode", ->
-      keystroke 'diw'
-
-      text().toBe "12345  ABCDE"
-      cursor().toEqual [0, 6]
-      register('"').toBe 'abcde'
+  ensure = (spec={}) ->
+    if spec.text?
+      text().toBe spec.text
+    if spec.cursor?
+      cursor().toEqual spec.cursor
+    if spec.register?
+      register('"').toBe spec.register
+
+    if spec.selectedBufferRange?
+      selectedBufferRange().toEqual spec.selectedBufferRange
+    if spec.selectedBufferRanges?
+      selectedBufferRanges().toEqual spec.selectedBufferRanges
+
+    if spec.selectedScreenRange?
+      selectedScreenRange().toEqual spec.selectedScreenRange
+    if spec.selectedScreenRanges?
+      selectedScreenRanges().toEqual spec.selectedScreenRanges
+
+    notEnsureNormalMode = [
+      spec.selectedBufferRange, spec.selectedBufferRanges
+      spec.selectedScreenRange, spec.selectedScreenRanges
+    ].some((bool) -> bool)
+    unless notEnsureNormalMode
       classListContains('operator-pending-mode').toBe(false)
       classListContains('normal-mode').toBe(true)
 
+  ensureKeystroke = (_keystroke, spec={}) ->
+    keystroke(_keystroke)
+    ensure(spec)
+
+  describe "the 'iw' text object", ->
+    beforeEach ->
+      text "12345 abcde ABCDE"
+      cursor [0, 9]
+
+    it "applies operators inside the current word in operator-pending mode", ->
+      ensureKeystroke 'diw',
+        text:     "12345  ABCDE"
+        cursor:   [0, 6]
+        register: 'abcde'
+
     it "selects inside the current word in visual mode", ->
-      keystroke 'viw'
-      selectedScreenRange().toEqual [[0, 6], [0, 11]]
+      ensureKeystroke 'viw',
+        selectedScreenRange: [[0, 6], [0, 11]]
 
     it "works with multiple cursors", ->
       addCursor [0, 1]
-      keystroke 'viw'
-      selectedBufferRanges().toEqual [
-        [[0, 6], [0, 11]]
-        [[0, 0], [0, 5]]
-      ]
+      ensureKeystroke 'viw',
+        selectedBufferRanges: [
+          [[0, 6], [0, 11]]
+          [[0, 0], [0, 5]]
+        ]
 
   describe "the 'iW' text object", ->
     beforeEach ->

      cursor [0, 9]

    it "applies operators inside the current word in operator-pending mode", ->
      keystroke 'di{'
      text().toBe "{}"
      cursor().toEqual [0, 1]
      classListContains('operator-pending-mode').toBe(false)
      classListContains('normal-mode').toBe(true)

    it "applies operators inside the current word in operator-pending mode (second test)", ->
      cursor [0, 29]
      keystroke 'di{'
      text().toBe "{ something in here and in {} }"
      cursor().toEqual [0, 28]
      classListContains('operator-pending-mode').toBe(false)
      classListContains('normal-mode').toBe(true)

  describe "the 'i<' text object", ->
    beforeEach ->

      cursor [0, 9]

    it "applies operators inside the current word in operator-pending mode", ->
      ensureKeystroke 'di[',
        text: "[]"
        cursor: [0, 1]

    it "applies operators inside the current word in operator-pending mode (second test)", ->
      cursor [0, 29]
      ensureKeystroke 'di[',
        text: "[ something in here and in [] ]"
        cursor: [0, 28]

  describe "the 'i\'' text object", ->
    beforeEach ->
