This project demonstrates a Node.js testing environment with Jest, fully containerized using Docker. It includes a setup to automate dependency installation and testing, making it portable and easy to run in any environment.
- Introduction
- Features
- Project Structure
- Setup and Installation
- Running Tests
- About Jest
- Contributing
- License
This project automates the testing process for a Node.js application using Jest as the testing framework. Docker is configured to ensure dependencies are consistently managed across different environments, which helps avoid "works on my machine" issues. The containerized setup is especially helpful for CI/CD pipelines or for developers who want a hassle-free testing environment setup.
- Automated Testing: Utilizes Jest for unit tests and integration tests.
- Containerized Setup: All dependencies are installed in a Docker container, making the setup consistent and portable.
- Easy Setup: Minimal setup required for users; clone the repository, build the Docker image, and start testing.
- Dockerfile: Configures the Docker image for this project, installs dependencies, and sets up Jest.
jest.config.js: Configures Jest options, such as testing environment, coverage reports, and verbose output.- Test Files: Located in the root directory, each test file targets a specific function, testing it for a range of possible inputs.
Follow the steps below to get the project set up on your local machine.
- Clone the repository:
git clone [Unit testing Using JEST](https://github.com/ZainabEman/Unit-Testing-Using-JEST-Framework.git) cd jest-docker-setup
A simple Node.js-based testing setup using Jest, designed for flexibility with or without Docker.
Run the container with the command below:
docker run -it --rm jest-projectIf you’re running the project outside of Docker, install dependencies with:
npm installYou can run tests in two ways: within the Docker container or directly using Jest on your machine.
To run all Jest tests in Docker, use:
docker run -it --rm jest-project npx jestIf you installed dependencies locally (without Docker), run:
npx jestJest is a popular JavaScript testing framework developed by Facebook. It’s designed with simplicity and zero-configuration testing in mind, providing functions like test, expect, and describe to structure and evaluate tests efficiently.
describe: Groups related tests for a function.test: Defines individual test cases.expect: Creates assertions to validate results against expected outcomes.- Matchers: Jest provides built-in matchers like
toBe,toEqual, andtoThrowfor common assertions.
Contributions are welcome!
Please open an issue or submit a pull request.
This project is licensed under the MIT License.