Skip to content

Sometime getting main-thread checker warning on Unit-test #926

Answered by mbrandonw
khairilushan asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @khairilushan,

this is happening because the .immediate scheduler simply performs its work right away, on whatever thread it happens to be on. So, in tests, when you run the reducer and cause the effect to await it switches to a new thread, and then delivers its output to the store on a background thread.

This doesn't happen when running the app because there you are using a regular DispatchQueue.main.

In order to get this to work you will need to use a live DispatchQueue.main in your tests, which means you will need to perform await Task.sleep in the test in order to wait for schedulers to do their work. This also means you will need to make your test async, which then means you will …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@khairilushan
Comment options

Answer selected by khairilushan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants