How to test Redux - a podcast by Kent C. Dodds

from 2021-01-30T18:12:01

:: ::

Hello everyone. So today I want to talk about testing redux. So I know that
I don't really use redox like a lot of people know that I am not a huge fan
of redux any redex project. I worked in would just became very difficult towork in. But I know that a lot of people are using redux and especially if
you are probably using redux tool kit, which is great.So anyway, as far as testing redex goes. You shouldn't actually ever be
testing redex. You pretty much always want to test the components that areusing redux.And only sometimes when you have maybe something that's really
complicated and redex or something you should probably extract thatcomplicated logic into its own pure function and test that by itself.
But most of the time you don't need to bother most the time just rest the
components that use redex you wrap your component inside of the the redexstore provider and everything and and and then just test it as if it's not
using redex and the benefit to this is if you decide that oh this statedoesn't need to be in redox.
I can move this to local state or whatever then that's
actually.Straightforward to do and the test will help you confirm that youdidn't break any behavior in the process of doing of doing that. And on top
of that, you can go the other way too. So if you decide, oh this stateneeds to be in redux, if you've written your test so that everything's
wrapped in the ReadX context provider, then moving it over to redex thetest should be able to tell you that you didn't make any mistakes in that
process either.So readax is an implementation detail. Don't bother testing read
explicitly. I don't test my action create.Ters I don't test yeah or when I
was using readx I didn't test the action creators didn't test the reducers.
I tested the components that use those things and I didn't mock those those
things.And on top of that you also get your map dispatched to props and whatever
else those I can't remember what those things are called anymore, but you
don't need to bother testing those in isolation you get those covered
because you're testing the component the connected version of the
component.So, you don't have to worry about refactors breaking your tests, the the
test can actually.Give you confidence in the refactor. Hopefully, that's
helpful. Have a awesome day. We'll see you around.

Further episodes of 3 Minutes with Kent

Further podcasts by Kent C. Dodds

Website of Kent C. Dodds