Updated 01/07/2024
Jest is a javaScript testing framework.
Pre Cursor
- Install Node so we can run the JS locally https://nodejs.org/en/download, check its installed with
node -v
npm init
, namejesttesting
and enter defaults, for test typejest
- this creates
package.json
npm install --save-dev jest
to install jest- create our root module
index.js
and test for itindex.test.js
The package.json file should look like
1 | { |
- Then to create a js file that the browser can use run
npm install -g webpack webpack-cli
- create
webpack.config.js
(it had to have the absolute path)
1 | module.exports = { |
- Run
webpack
, this creates the bundle in dist which should be browser friendly.
Life Cycle
Note that it
and test
are the same thing and you nest a describe
in a describe
1 | describe('unit of work should', () => { |
Update index.js
This is a simple example that redirects a user to a new version of the page when the js file is loaded in the master (so avalible on all pages)
Data driven
1 | describe('unit of work', () => { |
TBA
1 | expect(spy).toHaveBeenCalledTimes(1); |