BRIEFS logo BRIEFS

How to test Redux

01/30/2021 , 2m, 25s

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 to work 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 are using redux.And only sometimes when you have maybe something that's really complicated and redex or something you should probably extract that complicated 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 redex store 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 state doesn'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 you didn'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 state needs 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 the test 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.