Cannot read property webkitMatchesSelector of undefined - in tests


#1

Hi, I am trying to write tests for my package but I have endend pretty quickly. Problem is with line atom.commands.dispatch editorElement, ‘package-list-downloader:load-predefined-list’

If I use workspaceElement atom.views.getView(atom.workspace), it works. So I have two questions:

  1. Why I am getting error in case of Editor Element?
  2. Should I dispatch even on editor or on atom workspace?

{$} = require ‘atom-space-pen-views’

describe “PackageListDownloaderView”, ->
[editor, editorElement] = []

beforeEach ->
runs ->
editor = atom.workspace.getActiveEditor()
editorElement - atom.views.getView(editor)

describe “Predefined view”, ->

it "loads all categories when toggled", ->
  atom.commands.dispatch editorElement, 'package-list-downloader:load-predefined-list'

#2

Two things:

  1. If you doesn’t open a file first there won’t be an active editor to get, and no view neither.
  2. It seems that there’s a small delay between the moment an editor is created and the moment its view become available in the view registry. I had this issue in minimap when I changed the way I observed text editors. In the end I wait one frame before reading the view (see below).

https://github.com/fundon/atom-minimap/blob/master/lib/mixins/view-management.coffee#L83-L90