Waiting for Promise after activation in Spec


After reading @leedohm’s post at How do I activate a package in specs? I’ve been able to get my spec running, but I’m running into the following problem: my activation command activates my package as intended, but it also runs a command (@quickedit) that returns a promise. I’m trying to test whether this promise then opens a panel like so

.then ([text, start, end, file]) => #In the activation function
it "should show a panel", -> #in the spec
      activateAndThen ->
          quickEditorElement = workspaceView.querySelector ".quick-editor"
          quickEditorPanel = atom.workspace.panelForItem quickEditorElement

          expect(quickEditorPanel.isVisible()).toBe true #HERE

But I believe it only waits for the package to activate, not for my quickEdit function to resolve its promise seeing as this test fails. Does anyone know how to wait for this sort of event? The full code is here if anyone is willing to take a look at it in spec/quick-editor-spec


If you don’t want to expose the promise publicly (on your package that is), you can still test it’s side effects, so if you need to know if a panel was opened you can wait for it:

it "should show a panel", ->
    waitsFor -> workspaceView.querySelector ".quick-editor"

If the promise don’t create the panel the test will fail with the timeout, otherwise it’ll pass as soon as the selector query return anything but null.


Ah clever. Thank you!