jest (basics)

ref – https://medium.com/piecesofcode/testing-javascript-code-with-jest-18a398888838

> mkdir jestTest
> cd jestTest
> npm init

> npm install —-save-dev jest

then in package.json:

make sure the “scripts” key, and its values are there.

Test Custom function

Let’s define a custom function.
concat.js

Then we test that custom function

concat.test.js

Basically, we use expect(…).toBe(…)

to make sure the returned result from our custom function matches up with what’s in toBe(…).

.toBe() basically just checks that value is what you expect it to be.

Testing custom objects

We can also declare a custom object, and then expect(…).toBe(…) an object.

matchers.test.js

Is the object in question equals given object?

Declare a null. Test if its a null. Test if its defined.

doing addition/subtraction with numerics

Check for elements in an array

Match a character in a string

callback

First we define the function getMessage, where we take a callback object parameter.
In the function getMessage, we pass in a string “go Javascript!”.

Then in our test, we define the callback function. In turn we pass in this callback function into the getMessage.

The way we test for the callback is to expect the value inside the callback function to be the string “go Javascript!”