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

https://github.com/zafir100100/angular-component-testing-with-jasmine-and-karma

This repository contains unit tests for the LoginComponent in an Angular application. It ensures the login form behaves correctly, with validation rules and maximum length constraints.
https://github.com/zafir100100/angular-component-testing-with-jasmine-and-karma

angular component-testing jasmine karma

Last synced: about 1 month ago
JSON representation

This repository contains unit tests for the LoginComponent in an Angular application. It ensures the login form behaves correctly, with validation rules and maximum length constraints.

Awesome Lists containing this project

README

        

# Angular Component Testing with Jasmine & Karma

This repository contains unit tests for the `LoginComponent` in an Angular application. It ensures the login form behaves correctly, with validation rules and maximum length constraints.

## **Video**

https://github.com/user-attachments/assets/1e88049b-e069-43d0-b27f-3e84d25a5e64

## **Technologies Used**
- Angular (version 19)
- Jasmine & Karma (for testing)
- SweetAlert2 (for modal handling)

## **Test Scenarios**

### ✅ **Component Initialization**
- Should create the `LoginComponent`.

### ✅ **Form Controls**
- Should create a form with `username` and `password` fields.
- Should make the `username` and `password` fields **required**.
- Should mark the form as **invalid** when fields are empty.
- Should mark the form as **valid** when required fields are filled.

### ✅ **Form Validation Rules**
- Should make the `username` invalid if it **exceeds max length**.
- Should make the `password` invalid if it **exceeds max length**.
- Should make the `username` valid if it's **within max length**.
- Should make the `password` valid if it's **within max length**.

### ✅ **Login Functionality**
- Should return **true** when login is successful.
- Should return **false** when login fails with incorrect credentials.

### ✅ **SweetAlert2 Modal Handling**
- Should **dismiss SweetAlert modal after each test** by simulating `Esc` key or calling `Swal.close()`.

## **Setup & Run Tests**

### 📌 **Installation**
```bash
git clone https://github.com/your-username/angular-login-testing.git
cd angular-login-testing
npm install
```

### 📌 **Run Application**
```bash
ng s
```

### 📌 **Run Test**
```bash
ng test
```

## Screenshot (Application)

![image](https://github.com/user-attachments/assets/46c0da3b-f972-423b-995c-bce69c0dda1a)

## Screenshot (Test Report)

![image](https://github.com/user-attachments/assets/6545d43f-9ed6-46f3-b064-40582663f6f3)