This repository contains a basic setup for unit testing using Jest. It includes simple examples of unit tests for addition, subtraction, and fetching data.
├── src
│ └── math.js # Contains the functions to be tested
├── tests
│ ├── add.test.js # Unit test for the add function
│ ├── subtract.test.js # Unit test for the subtract function
│ └── fetchData.test.js # Unit test for the fetchData function
├── package.json # Project configuration and dependencies
└── README.md # Project documentation (this file)
To get started with this project, you will need to have Node.js and npm (Node Package Manager) installed.
First, clone the repository and navigate to the project directory:
git clone https://github.com/devonshigaki/unit-tests.git
cd unit-testsThen, install the required dependencies:
npm installTo run the Jest tests, simply use the following command:
npm testThis will execute all test files located in the tests directory and display the results in the terminal.
Adds two numbers and returns the result.
Example:
const { add } = require('./src/math');
console.log(add(2, 3)); // 5Subtracts the second number from the first and returns the result.
Example:
const { subtract } = require('./src/math');
console.log(subtract(5, 3)); // 2Asynchronously fetches data and returns it.
Example:
const { fetchData } = require('./src/math');
fetchData().then(data => console.log(data)); // 'data'If you wish to contribute to this project, feel free to fork the repository, make your changes, and submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
For any inquiries or issues, please contact devonshigaki.