Instructor: In the last section
we put together a test around our comments reducer.
At the very end of the video, I made a small change
to the test to make sure that the test failed
and it looked like it did in fact fail the way I expected.
So I'm now gonna go back over
to my test file and restore it to its working state.
Cool.
Now if I go back to my list of tests, I wanna write
remember we also wanted to make sure
that if we call the reducer
with an action that has an unknown type
we should not see an error
or nothing should really just go wrong.
So this test will be pretty straightforward.
I'm gonna add in another it statement
inside my test file and I'll give it a description
of something like, handles action with unknown
type.
So in this case,
we can write an even more terse test than we did previously.
All we really have to do is call our comments reducer.
We can pass in an initial state if we want to
but we definitely don't have to.
And then we can pass in an action that does not
even have to have a payload or a tight property.
So passing in an empty object essentially counts as passing
in an action with an unknown type because it has no type.
If you wanna be a little bit more explicit,
you could always pass in
an actual type property with some random string here.
It's totally up to you.
Really, both of them are more
or less the same way of testing this reducer.
You can really take it either way.
So then all we have to do here is probably
take whatever gets returned from comments reducer.
I'll again call it new state.
And then I'll write an expectation to say
that new state should simply be an empty array.
So we're just gonna kinda make the case to say,
Hey, you know what?
Comments reducer did not throw an error
and as usual as expected,
it's just gonna return whatever state it was provided
which should be an empty array.
So I'll say expect new state to equal empty array,
like so.
And that's pretty much it.
Honestly, these kind of unknown action type tests right here
you can definitely do them.
I personally don't find them the most useful thing
in the world.
I think it's a lot more useful to write tests
around actual action types that you know are going to come
across the reducer.
All right, so we'll flip back over
to our test suite really quick
and just make sure this is passing as well.
And it looks like we're good to go.
Now this is one case where I won't make you try to
make the test fail here
cuz it's kind of hard to make this test fail.
So if you wanna give it a try, go for it.
Otherwise, let's continue in the next section
and we'll start writing some tests around the next part
of our application, which will be our
SaveComment action creator.