Editor `onDidiStopChanging` in spec

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?

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.


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.


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

emitter = new Emitter


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

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.

@redbassett This is how I do this in Pigments:

1 Like

Thanks @abe, that should work great.