Editor `onDidiStopChanging` in spec


#1

I have an onDidStopChanging method for the current editor in my package. When running the package, this method is called as expected when the buffer is changed, however in the package’s spec, if I insertText on the editor, the onDidStopChanging method isn’t called. How do I insert text into the editor as if it was typed by the user?


#2

Is it really necessary to work with onDidStopChanging in your spec ?
You are testing your package and not Atom’s TextEditor, so you should just assume that Atom’s components work.

I would simply call insertText and then fire the callback function manually.


#3

That makes sense. It does isolate the test to the package code. Currently I have a number of lines of code inside the callback, however if I put that all in another method and just use the change callback to trigger the other method, that could easily be triggered manually by the test.

Thanks!


#4

Is it possible to fire the event like how Atom would? Something like:

emitter = new Emitter

editor.insertText('yep')
emitter.emit('on-did-stop-changing')

I couldn’t get this to work, but I don’t know asynchronous events very well.


#5

In theory, you could trigger the event, but @deprint is spot-on that good testing is limited to the package’s code, and what is called for here is a unit test of the callback.


Package not triggered in spec / no onDidStopChanging event
#6

@redbassett This is how I do this in Pigments:


#7

Thanks @abe, that should work great.