An open API service indexing awesome lists of open source software.

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

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
*/
```