https://github.com/traveltimn/testing-jest
Introduction to Jest testing from Code Institute 5P course
https://github.com/traveltimn/testing-jest
javascript jest
Last synced: 19 days ago
JSON representation
Introduction to Jest testing from Code Institute 5P course
- Host: GitHub
- URL: https://github.com/traveltimn/testing-jest
- Owner: TravelTimN
- Created: 2021-07-08T08:56:33.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-07-08T10:21:30.000Z (almost 5 years ago)
- Last Synced: 2025-06-15T06:49:05.301Z (12 months ago)
- Topics: javascript, jest
- Language: Dockerfile
- Homepage:
- Size: 43 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Testing with [Jest](https://jestjs.io/)
## Initialize NPM
- `npm init`
- hit `` for all options except for **test command:**, and type `jest`.
## Use Jest in a dev environment
- Adds Jest to a list called Dev Dependencies
- `npm install --save-dev jest`
## Run Jest
- `npm test`
## Describing Tests
Sample Test in plain English
- I want to test a calculator.
- I am going to test the addition function.
- I want to get the result of 42.
- I expect 20 + 22 to equal 42.
Sample Test using Jest
```javascript
describe("calculator tests", () => {
describe("addition tests", () => {
test("should return 42", () => {
expect(addition(20, 22)).toBe(42);
});
});
});
```
- `.toBe()` is a type of "Matcher".
- View [Jest Matchers](https://jestjs.io/docs/using-matchers).
---
## **IMPORTANT !**
### Due to a change in Jest's default configuration, you need to add the following code to the top of your `button.test.js` file:
```javascript
/**
* @jest-environment jsdom
*/
```