 describe "Welcome", ->
-  openFileTimeout = 200
+  editor = null
 
   beforeEach ->
     waitsForPromise ->
       atom.packages.activatePackage("welcome")
-    waits(openFileTimeout)
+    waitsFor ->
+      editor = atom.workspace.getActiveTextEditor()
 
   describe "when activated for the first time", ->
     it "shows the welcome buffer", ->
-      editor = atom.workspace.getPaneItems()[0]
       expect(editor.getText()).toMatch(/Welcome to Atom/)
 
   describe "when activated again", ->

      atom.workspace.getActivePane().destroy()

      atom.commands.dispatch(workspaceElement, 'welcome:show-welcome-buffer')
      waits(openFileTimeout)

      runs ->
        editor = atom.workspace.getPaneItems()[0]
        expect(editor.getText()).toMatch(/Welcome to Atom/)


      waitsForPromise ->
        atom.packages.activatePackage("welcome")
      waits(200)

    it "doesn't show the welcome buffer", ->
      expect(atom.workspace.getPaneItems().length).toBe(0)
