 
       runs ->
         atom.packages.deactivatePackage("tree-view")
-        atom.packages.activatePackage("tree-view")
-        treeView = atom.workspaceView.find(".tree-view").view()
-
-        expect(treeView).toExist()
-        expect(treeView.selectedEntry()).toMatchSelector(".file:contains(tree-view.js)")
-        expect(treeView.find(".directory:contains(dir1)")).toHaveClass("expanded")
+
+      waitsForPromise ->
+          atom.packages.activatePackage("tree-view")
+
+      runs ->
+          treeView = atom.workspaceView.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", ->
       atom.workspaceView.attachToDom()
       treeView.focus()
       expect(treeView.list).toMatchSelector ':focus'
       atom.packages.deactivatePackage("tree-view")
-      atom.packages.activatePackage("tree-view")
-      treeView = atom.workspaceView.find(".tree-view").view()
-      expect(treeView.list).toMatchSelector ':focus'
+
+      waitsForPromise ->
+        atom.packages.activatePackage("tree-view")
+
+      runs ->
+        treeView = atom.workspaceView.find(".tree-view").view()
+        expect(treeView.list).toMatchSelector ':focus'
 
     it "restores the scroll top when toggled", ->
       atom.workspaceView.height(5)

        atom.project.setPath(dotGit)
        atom.packages.deactivatePackage("tree-view")
        atom.packages.packageStates = {}
        {treeView} = atom.packages.activatePackage("tree-view").mainModule
        expect(treeView).toBeFalsy()

  describe "serialization", ->
    it "restores expanded directories and selected file when deserialized", ->

    atom.project.setPath(atom.project.resolve('tree-view'))
    atom.workspaceView = new WorkspaceView

    waitsForPromise ->
      atom.packages.activatePackage("tree-view")

    runs ->
      atom.workspaceView.trigger 'tree-view:toggle'
      treeView = atom.workspaceView.find(".tree-view").view()
      treeView.root = treeView.find('ol > li:first').view()
      sampleJs = treeView.find('.file:contains(tree-view.js)')
      sampleTxt = treeView.find('.file:contains(tree-view.txt)')

      expect(treeView.root.directory.getSubscriptionCount()).toBeGreaterThan 0

  describe ".initialize(project)", ->
    it "renders the root of the project and its contents alphabetically with subdirectories first in a collapsed state", ->
