Instructor: So we've got the first part
of our simulate helper right here,
where we actually trigger an event.
We need to take care of the second part
where we will update the value of the HTML element
if one was passed into this function.
And so this part is a little bit more straightforward.
We'll just check to see if a value was passed in.
Then this .val value.
And so this .val,
this again, is a reference
to the HTML element that was selected.
And val is a jQuery method
that sets the value of the HTML element.
And so this is really relevant or used
whenever we have a input,
or a text area, or similar.
And so we just pass in the new value that we want,
and boom, there we go.
So let's go ahead and save this,
check out the console,
and it looks like we've got another spec passing,
we're down to just one more error.
I bet you it's gonna be very close related
to the fact that we have not set yet jquery-chai,
down here at the bottom.
So let's go ahead and do that right now,
since it should be pretty quick.
So the first thing we need to do to set up chai-jquery
is we need to import the library,
we've not yet imported it.
So we'll import chaiJquery from chai-jquery.
And then to set up a plugin
or a additional set of matchers for Chai,
we need to get reference to the Chai library.
Right now we've only pulled in the Expect library.
So to pull in the entire Chai library,
we'll add in Chai, like so.
Now down back at the bottom,
we'll pass in chaiJQuery,
and we're gonna call this, it's a function
that we're gonna call with chai, chai.util,
and our instance of jQuery
that we've already set up.
Remember, this is kind of
that fanangled instance of jQuery
that we already pulled off of jsdom up here.
So again, this method signature
is something you can look up
by looking directly at the Chai jQuery docs.
It's something you do not need to memorize,
it's something that I got by looking at the documentation,
which you can certainly do as well.
All right.
Let's save this and see how we're doing.
And it looks like, hey,
all of our specs are passing,
green across the board.
So I hope you've enjoyed this kinda walkthrough
setting up the test utils file,
or the test helper file.
I know that it's been really confusing,
there's probably been a lot of places where you said,
"Wait, what the heck just happened?"
Again, the idea here was
to give you just a little bit of a hint
at how this got set up.
When I did the initial setup for this test helper,
this is a test helper
that I've used on several projects of my own,
it took me quite a lot of tweaking.
You know, a lot of work went into this simple,
you know, it's only about 39 lines of code,
but it took me many, many, many hours
to get everything set up just right.
So again, this was just
to give you a little bit of taste of
what's going on behind the scenes.
All right.
I'll go ahead and catch you in the next section.