A comprehensive demonstration project for JavaScript unit testing using the Jasmine testing framework. This project showcases behavior-driven development (BDD) principles, testing best practices, and provides practical examples for learning effective testing strategies.
This repository serves as a complete guide and reference for JavaScript unit testing with Jasmine. It includes:
- Real-world examples of classes and functions with comprehensive test suites
- Best practices for organizing and structuring tests
- Advanced testing patterns including spies, mocks, and asynchronous testing
- CI/CD integration with GitHub Actions
- Comprehensive documentation and guides
- Web browser (Chrome, Firefox, Safari, or Edge)
- Git
- Node.js (optional, for npm scripts and CI/CD)
-
Clone the repository:
git clone git@github.com:hkevin01/javascript-unit-test-jasmine.git cd javascript-unit-test-jasmine -
Open in browser:
# Open SpecRunner.html in your browser open SpecRunner.html # or firefox SpecRunner.html
-
Or use a local server (recommended):
# Using Python 3 python -m http.server 8000 # Using Node.js (if you have http-server installed) npx http-server # Then open http://localhost:8000/SpecRunner.html
javascript-unit-test-jasmine/
βββ .github/ # GitHub workflows and templates
β βββ workflows/
β β βββ test.yml # CI/CD pipeline
β βββ ISSUE_TEMPLATE.md # Bug report template
βββ .copilot/ # GitHub Copilot configuration
β βββ copilot-instructions.md
βββ assets/ # Static assets
β βββ css/
β β βββ jasmine-custom.css # Custom Jasmine styling
β βββ images/ # Project images
β βββ lib/ # Third-party libraries
βββ docs/ # Documentation
β βββ project-plan.md # Project roadmap
β βββ testing-guide.md # Comprehensive testing guide
βββ spec/ # Test specifications
β βββ support/ # Test support files
β βββ *.spec.js # Test files
βββ src/ # Source code
β βββ models/
β β βββ Person.js # Person class example
β βββ utils/ # Utility functions
β βββ Calculator.js # Calculator class example
βββ .gitignore # Git ignore rules
βββ SpecRunner.html # Jasmine test runner
βββ README.md # This file
A comprehensive calculator with mathematical operations:
- Basic arithmetic (add, subtract, multiply, divide)
- Advanced operations (square root, power)
- Error handling (division by zero, negative square roots)
- Operation history tracking
- Power state management
An object-oriented example demonstrating:
- Constructor patterns and property management
- Friend and hobby management
- Input validation and error handling
- String manipulation and formatting
- Complex object interactions
- Understanding describe and it blocks
- Writing your first test
- Basic matchers and assertions
- Setup and teardown with beforeEach/afterEach
- Testing error conditions
- Custom matchers
- Spies and mocking
- Asynchronous testing
- Integration testing
- Test organization
- Performance considerations
- Maintainable test code
- Describe blocks for test organization
- It blocks for individual specifications
- Matchers for assertions (
toEqual,toBe,toContain, etc.) - Setup/Teardown with before/after hooks
- Spies for function monitoring and mocking
- Custom matchers for domain-specific assertions
- AAA Pattern (Arrange, Act, Assert)
- Test isolation and independence
- Edge case testing
- Error condition testing
- Asynchronous code testing
The project includes custom CSS styling for the Jasmine test runner with:
- Modern, clean interface
- Responsive design for mobile devices
- Color-coded test results
- Progress indicators
- Enhanced readability
Automated testing with GitHub Actions:
- Runs tests on multiple Node.js versions (16.x, 18.x, 20.x)
- Generates coverage reports
- Validates code quality
- Automatic deployment of test results
- Project Plan - Complete project roadmap and objectives
- Testing Guide - Comprehensive guide to writing tests with Jasmine
- GitHub Copilot Instructions - AI assistance configuration
Contributions are welcome! Please read our contributing guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Jasmine Framework - For the excellent testing framework
- Evan Hahn's Tutorial - Original inspiration and guidance
- JavaScript Testing Best Practices - For comprehensive testing guidelines
If you have questions or need help:
- Check the documentation
- Browse existing issues
- Create a new issue using our template
Ready to start testing? Here's what you can do:
- Explore the examples - Look at the Calculator and Person classes
- Run the tests - Open SpecRunner.html and see tests in action
- Read the guides - Check out our comprehensive testing documentation
- Write your own tests - Use our examples as templates for your projects
- Contribute - Help improve this learning resource
Happy Testing! π§ͺβ¨