-: So, we are all done with our application now,
we have written down all of our specs.
But, I don't know, there is still
a little bit of unanswered questions here.
We have got all this mystery code inside of the test helper
and heck, we've kind of also been flying around
with terms like, say, 'mentioning chai'
but I have also been 'mentioning mocha'
in certain places as well, so there is still
a couple of unanswered questions,
inside this application I want to go over.
If you are completely happy with learning tests
as you have so far, and you want to move on
to the next section, feel free to do so,
but if you are really interested in
some of the behind the scenes, you know,
kind of figuring how this stuff really works,
than I encourage you to stick around for
the next couple videos and let's do kind of
a deep dive and figure out how things
are really taking here.
So, the first thing I want to talk about is some
of the imports that we are including into
the spec file right here, into this test helper.
So, at the very top we have got stuff like
'jquery', 'react', 'react-dom', 'jsdom'
and then very importantly, I want to talk
a little bit about 'chai', right here.
So, you can see that we are pulling of
the 'chai' library and the 'expect' key word,
and we have been using 'expect'
all over the place.
So, it turns out that 'expect' is coming from
the 'chai' library, but again, what is 'chai'
and how different it is from say, 'mocha',
what is 'chai' doing, what is 'mocha' doing.
So, let's investigate that relationship
a little bit more.
I am going to pull out a diagram up
in the screen, it's going to kind of help
illustrate the point here.
So, the idea behind this diagram is to kind of
talk a little bit about
the needs of a testing suite.
Don't try to focus too much on the stuff
on the right hand side just yet,
let's just look at the stuff on
the left hand side.
So, the needs of our testing suite
are summarized by these two boxes right here,
whenever we are writing test, we need something
to actually run the test. Right?
We need something to read all the java script
files in, we need something to execute
on the command line and give us the report back,
we need something to handle errors,
we need a entire apparatus
to take care of all this, something that, say,
loads our tests, runs them one by one and then
cleans up after all the specs are done
and generates a report.
So, that's the job of 'mocha',
that's what 'mocha' does, 'mocha' doesn't
actually do, say, make any assertions
about anything, or actually test anything,
it's just a testing apparatus.
So, you will notice that inside of our entire
test helper here, and inside of a lot
of our other files, we never really did a lot
with 'mocha' directly.
The 'describe', 'beforeEach' and 'it' were only
interfaced to 'mocha' itself, everything else
was really going on behind the scenes.
So, along with something to run our tests,
we need something to write our tests with,
something to actually say;
Okay, given this subject, given this, say,
component or function or adduser
or action creator or whatever it might be.
I expect this component to contain
the text 'asdf'.
Or I expect this number to be equal to five.
Or I expect this object to be 'nra'.
Those are all things that are helping us with
making assertions about a certain property,
or a certain aspect of the test subject,
and so, that is really a little bit more of
what we think about when we think about testing
and that is the responsibility of 'chai',
'chai' is a hundred percent responsible for all
the actual individual assertions that we used
in our tests, it is also the source of a lot
of the documentation we were looking at.
So, we have pulled out very briefly the 'chai'
documentation here, which you can get to,
by just doing google search for 'chaijs'.
Inside of this documentation, you will find
all these different matchers, we only used one
in our case, the 'instance of' matcher
for the ray, but there is many other properties
on here or many other matchers that you might
want to know about.
Also notice that some of the matchers in here
are repeated in the documentation that we are
looking at for 'chai jquery'.
So, with 'chai jquery' we may use
this '.exist' matcher and so, other libraries
that kind of, are loaded on top of 'chai',
like 'chai jquery', that is a tough one,
some of these other libraries that we load up
redefine these matchers or augment the matchers
in some fashion, and so, for example,
'chai jquery' says if they're making
an expectation on a 'jquery' object, then I want
to use this special matcher '.exist' otherwise,
if it is just like, you know, 'say a string' or
'null' or 'undefined' or something like that.
'Mocha', you can take care of this one,
'chai', you can take care of this one,
'chai jquery', doesn't need to care
about this one, this is some boring
test subject.
So, we can add other libraries on top of 'chai'
that augment the matchers that
we have access to.
So, that is a little bit more about the purpose
of 'mocha' and 'chai', now that we know
a little bit more, we can do a little bit more
digging into our test helper inside
of the next section. I will see you there.