 
       describe "when a file entry is selected", ->
         it "does nothing", ->
-          treeView.root.find('.file').click()
-          treeView.trigger 'tree-view:expand-directory'
+          waitsForFileToOpen ->
+            treeView.root.find('.file').click()
+
+          runs ->
+            treeView.trigger 'tree-view:expand-directory'
 
     describe "tree-view:collapse-directory", ->
       subdir = null

          lastDir = treeView.root.find('.directory:last').view()
          fileAfterDir = lastDir.next().view()
          lastDir.expand()
          fileAfterDir.click()

          treeView.trigger 'core:move-up'
          expect(lastDir.find('.entry:last')).toHaveClass 'selected'

      describe "when there is an entry before the currently selected entry", ->
        it "selects the previous entry", ->
          lastEntry = treeView.root.find('.entry:last')
          lastEntry.click()

          treeView.trigger 'core:move-up'

          expect(lastEntry.prev()).toHaveClass 'selected'

      describe "when there is no entry before the currently selected entry, but there is a parent directory", ->
        it "selects the parent directory", ->

  describe "serialization", ->
    it "restores expanded directories and selected file when deserialized", ->
      treeView.root.find('.directory:contains(dir1)').view().click()

      waitsForFileToOpen ->
        sampleJs.click()

      runs ->
        atom.deactivatePackage("tree-view")
        atom.activatePackage("tree-view")
        treeView = rootView.find(".tree-view").view()

        expect(treeView).toExist()
        expect(treeView.selectedEntry()).toMatchSelector(".file:contains(tree-view.js)")
        expect(treeView.find(".directory:contains(dir1)")).toHaveClass("expanded")

    it "restores the focus state of the tree view", ->
      rootView.attachToDom()
