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.
- Host: GitHub
- URL: https://github.com/zafir100100/angular-component-testing-with-jasmine-and-karma
- Owner: zafir100100
- Created: 2025-03-28T11:47:41.000Z (about 2 months ago)
- Default Branch: master
- Last Pushed: 2025-03-31T07:51:36.000Z (about 1 month ago)
- Last Synced: 2025-03-31T08:31:35.104Z (about 1 month ago)
- Topics: angular, component-testing, jasmine, karma
- Language: TypeScript
- Homepage:
- Size: 138 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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)

## Screenshot (Test Report)
