Skip to content

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.

Notifications You must be signed in to change notification settings

zafir100100/Angular-Component-Testing-with-Jasmine-and-Karma

Repository files navigation

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

Desktop.2025.03.28.-.18.37.25.04.mp4

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

git clone https://github.com/your-username/angular-login-testing.git
cd angular-login-testing
npm install

📌 Run Application

ng s

📌 Run Test

ng test

Screenshot (Application)

image

Screenshot (Test Report)

image

About

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.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published