     pack = null
     beforeEach ->
       atom.config.set('core.themes', ["theme-with-index-less"])
-      atom.themes.activateThemes()
-      pack = atom.themes.getActiveThemes()[0]
-      uiWatcher = new UIWatcher()
+      waitsForPromise ->
+        atom.themes.activateThemes()
+      runs ->
+        uiWatcher = new UIWatcher()
+        pack = atom.themes.getActiveThemes()[0]
 
     afterEach ->
       uiWatcher.destroy()

  describe "when a package global file changes", ->
    beforeEach ->
      atom.config.set('core.themes', ["theme-with-ui-variables", "theme-with-multiple-imported-files"])
      atom.themes.activateThemes()
      uiWatcher = new UIWatcher()

    afterEach ->
      uiWatcher.destroy()


    it "unwatches when a theme is deactivated", ->
      atom.config.set('core.themes', [])
      waitsFor ->
        not uiWatcher.watchedThemes["theme-with-multiple-imported-files"]

    it "watches a new theme when it is deactivated", ->
      atom.config.set('core.themes', ["theme-with-package-file"])
      waitsFor ->
        uiWatcher.watchedThemes["theme-with-package-file"]

      runs ->
        pack = atom.themes.getActiveThemes()[0]
        spyOn(pack, 'reloadStylesheets')

        expect(pack.name).toBe "theme-with-package-file"

        watcher = uiWatcher.watchedThemes["theme-with-package-file"]
        watcher.entities[2].emit('contents-changed')
        expect(pack.reloadStylesheets).toHaveBeenCalled()
