I’m trying to write automatic tests for CodeMirror.
The way I do it now, i I do
const state = // make state
const parent = document.createElement("div");
new EditorView({parent, state});
return parent;
And then I write tests on parent
. It works great!
But everyonce in a while, like once every 20 runs, random tests fail. And they fail, because parent
don’t have applied styles.
I think new Editor({parent, state})
doesn’t immediately apply the view to the parent, and sometimes there’s a race condition, where test does assertion before the code mirror apply its styles.
I did a test, and when I apply 100ms “wait” in the tests, the problem goes away, however I know I don’t want to do it.
So my question is, how to “be notified” when new EditorView()
“finished” updating the node? I would like to set an event, or maybe some callback of some kind?
I was under the impression that when new EventView()
constructor returns, then its ready, but its not, because this random tests 1 in 20 runs fails.
Or is it so that it truly does return after it fails, and its my testing framework that messes it up?