Skip to content

ZainabEman/Unit-Testing-Using-JEST-Framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jest-Docker-Setup Project

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.

Table of Contents

Introduction

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.

Features

  • 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.

Project Structure

  • 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.

Setup and Installation

Follow the steps below to get the project set up on your local machine.

Prerequisites

  • Docker installed on your machine.
  • Node.js installed, if you prefer running Jest without Docker.

Installation

  1. Clone the repository:
    git clone [Unit testing Using JEST](https://github.com/ZainabEman/Unit-Testing-Using-JEST-Framework.git)
    cd jest-docker-setup
    

🧪 Jest Testing Project

A simple Node.js-based testing setup using Jest, designed for flexibility with or without Docker.


🚀 Run the Docker Container

Run the container with the command below:

docker run -it --rm jest-project

📦 Install Dependencies Manually (if Running Outside Docker)

If you’re running the project outside of Docker, install dependencies with:

npm install

✅ Running Tests

You can run tests in two ways: within the Docker container or directly using Jest on your machine.

🔹 Running Tests in Docker

To run all Jest tests in Docker, use:

docker run -it --rm jest-project npx jest

🔹 Running Tests Locally

If you installed dependencies locally (without Docker), run:

npx jest

📘 About Jest

Jest 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.

🧰 Jest Functions Used

  • 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, and toThrow for common assertions.

📚 Further Reading on Jest


🤝 Contributing

Contributions are welcome!
Please open an issue or submit a pull request.

License

This project is licensed under the MIT License.


About

A lightweight Node.js project setup for running unit tests with Jest. Supports both local and Docker-based test execution workflows. Ideal for fast, isolated, and scalable JavaScript testing environments.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors