How code testing packages-commands is supposed to work?
The problem I’m facing is that the specs dealing with a package command shows seemingly random behaviour. In particular I’ve four tests that do similar work, and the last of them often (not always) fails. I wonder if the problem can be ascribed to the activation of the package being a promise.
Here is what I do in my beforeEach method:
beforeEach -> atom.workspaceView = new WorkspaceView(); atom.project.setPath path.join(__dirname, 'fixtures') atom.workspaceView.openSync('sample.html') atom.workspaceView.attachToDom(); @editorView = atom.workspaceView.getActiveView(); @editor = @editorView.getEditor() atom.packages.activatePackage("language-html")
and here is what I do in one of the specs:
it 'closes the first non closed tag', -> @editor.setCursorBufferPosition(new Point(5,14)) @editorView.trigger('language-html:close-tag') cursorPos = @editor.getCursorBufferPosition() insertedText = @editor.getTextInRange( new Range([5,14], [5,18]) ) expect( cursorPos ).toEqual( new Point(5, 18) ) expect( insertedText ).toEqual('</a>')
Any best practice to follow? Is there any documentation about this topic?