Since 2013 (see I66520e ) we've been using an event listener in our tests to determine the current DM selection. This won't work reliably in the case where another listener for the same event changes the selection and itself causes a second event to be emitted simultaneously: the selections may not arrive in the correct order.
It turns out this can happen in our backspace tests; in https://gerrit.wikimedia.org/r/#/c/303335/4 I observed that the nested emits are as follows:
First, ve.dm.Surface emits 'select' with selection 3,3 . This ends up calling ve.ce.Surface#showModelSelection , which does ve.ce.SurfaceObserver#pollOnceInternal, which signals a branchNodeChange to ve.ce.Surface#handleObservedChanges, which calls ve.dm.Surface#change, which emits a (nested) 'select' with selection 2,2. These two simultaneous select events hit the listener in ve.ce.Surface.test.js#ve.test.utils.runSurfaceHandleSpecialKeyTest in the wrong order.
Therefore, we should use ve.dm.Surface#getSelection instead, unless there are problems with that (it was suggested that back in 2013 there were: see https://gerrit.wikimedia.org/r/#/c/87666/12/modules/ve/test/ce/ve.ce.Surface.test.js ), and discrepancies in our tests should be corrected accordingly.