Waiting for Promise after activation in Spec


#1

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
        ...
        @panel.show()
//
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


#2

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.


#3

Ah clever. Thank you!