Is there a way to debug how callbacks are called, when firing an event with testing-library?[SOLVED]
Hey,
I am having a hard time testing my code and would like to find out if and how some of my event handlers are actually being called, when I run
(continuation in thread)
fireEvent.click()
on a button.
Some background: I am running solid inside a Tauri-Application which works very well.
However my issue is, that on the click of a button nothing observable seems to happen (it works perfectly fine in the real running application).
Basically what I am trying to do, is to setup some stores, render my app, find a button that should start a timer, advance these timers by using vitests fake timers and afterwards inspect, that a stop button is being rendered and the time has been adjusted accordingly.
My current (simplified without timers) test looks like this:
(continuation in thread)
3 Replies
The relevant part of my component (also simplified):
timeEntries
and runningTimer
are both stores which reside inside their own files.
runningTimeEntrySelectors
basically look like this (simplified):
What I noticed is, that the fireEvent
call does not seem to lead to the runningTimer
-store to be updated at all.
Any idea what I could be doing wrong here? Thanks in advance
Ok, I think I made at least some progress:
My call to mockIPC
from Tauri was probably wrong. I should not wrap the click handler with that. Instead I needed to mock the actual backend commands (which makes sense).
Now I am also able to log from the click handler. Which answers my initial question.
The only issue I am still having is related to advancing fake timers - however before I open a new issue for that, I'll have a look at this with a fresh mind tomorrow 😄Fake timers are related to vitest, not to testing-library. However, I will try to support you to the best of my abilities.
Thanks a ton @lexlohr your effort is really appreciated. (Actually its amazing to see how much help you provide over here in the discord and how fast you usually respond! ❤️ )
Ha, got it to work (and learned a ton in the process 😊)
The last issue I was having, was that the interval I was running had an
async
callback and I accidentally used vi.advanceTimersByTime
instead of await vi.advanceTimersByTimeAsync(...)