-: In the last section, we introduced Moxios
into our test suite.
However, it looks like our test suite is failing still
particularly the one test that is trying
to fetch a list of comments and display all
of them on the screen.
Now at least we have a better failure
than what we had before.
Previously your entire test suite might
have been just been exiting back out
to the command line
so hopefully you're at least seeing
seeing something a little bit more positive
at this point.
Let's take a look at a diagram really quick
and try to get a better idea of why our test
is still failing.
All right, so this is a timeline
of what is happening inside of our integration
test right now.
At present were triggering that
or simulating that click event on the
fetch comments button.
When we trigger that click event
our action creator is definitely being called
no doubt about that
and inside that action creator we are issuing a request
now when that request is issued
right after that is where our trouble
starts to occur.
So when we issue that request it takes
a tiny tiny bit of time for Moxios
to see that outgoing request
intercept it and then respond back with that
fake list of comments that we just put together.
So that tiny bit of time that it takes Moxios
to kick in is the source of all of our troubles.
Cause the problem is
back over here
you and I are calling that simulate function
simulate click on that button
so this line of code right here
triggers the request and then in the very
next instant the very next micro second
we then look at that wrapped element
and try to find the number of LI's inside of it.
And so the problem is this tiny little gap
in time right here this is
what this dotted line is meant to represent.
After we issue that request we then
instantly check to see if those 2 LI's are visible
and then a tiny very small amount of time
Moxios finally kicks in and says
hey I got this request I'm going to respond
with a fake list of comments.
So then a millisecond later the request succeeds
the reducer picks up the comments
and the comment list gets rendered on the screen
so that's the cause of our issue right now.
To solve this you and I are going to introduce
a tiny arbitrary little delay
between issuing that request
and when our test weed tries to find that list of comments.
So essentially we're going to do this.
When we issue that request
we're going to introduce this little tiny
delay right here so that Moxios
has time to intercept the request
and respond with the fake list of comments.
So let's take a quick pause right here
now that we've got a better idea of what's going on
we'll continue in the next section
and we're going to figure out how we're
going to introduce this tiny little pause.