jest + react + autocompletion unit test

hello! im writing unit tests for my code editor component. i did bind Tab to start my own custom autocompletion. How can i simulate the Tab keypress and activate the autocompletion? I am using the react testing library for the unit tests. I also referenced this site but i am unable to figure out how to start autocompletion with Tab. I even tried to call the startCompletion passing in the view, but that still didn’t work :frowning: thank you!

Maybe it did, but you were tripped up by the fact that completion happens asynchronously?

hi thanks! you were right, it did call it. i put a console log inside the autocomplete function and i did see it print out. But for some reason, i’m unable to spyOn the request. :thinking: Besides calling startCompletion manually… is there a way to simulate the Tab keypress? Thank you!

hi @marijn! when you mentioned that completion happens asynchronously, does that mean if i were to manually trigger a startCompletion, i should wait for the autocomplete tooltip to render before i assert anything? thanks!

Yes, that’s what it means.

1 Like

thank you!