     it "reloads the snippets", ->
       jasmine.unspy(window, "setTimeout")
       jasmine.unspy(snippets, 'loadAll')
-      spyOn(atom.packages, 'getLoadedPackages').andReturn []
+      spyOn(snippets, 'loadPackageSnippets').andCallFake ->
+        process.nextTick -> snippets.doneLoading()
       configDirPath = temp.mkdirSync('atom-config-dir-')
       spyOn(atom, 'getConfigDirPath').andReturn configDirPath
       snippetsPath = path.join(configDirPath, 'snippets.cson')

      jasmine.unspy(snippets, 'loadAll')
      spyOn(atom.packages, 'getLoadedPackages').andReturn [packageWithSnippets, packageWithBrokenSnippets]
      spyOn(atom, 'getConfigDirPath').andReturn configDirPath

    it "loads non-hidden snippet files from all atom packages with snippets directories, logging a warning if a file can't be parsed", ->
      spyOn(console, 'warn')


describe "Snippets extension", ->
  [buffer, editorView, editor, snippets] = []

  beforeEach ->
    atom.workspaceView = new WorkspaceView
    atom.workspaceView.openSync('sample.js')
    spyOn(Snippets, 'loadAll')

    waitsForPromise ->
      atom.packages.activatePackage('language-javascript')

    waitsForPromise ->
      atom.packages.activatePackage("snippets").then ({mainModule}) ->
        snippets = mainModule

    runs ->
      editorView = atom.workspaceView.getActiveView()
      editor = atom.workspaceView.getActivePaneItem()
      buffer = editor.getBuffer()
