README
¶
Liveflux JavaScript Tests
This directory contains Jasmine test specifications for the Liveflux JavaScript modules.
Test Structure
runner.html- Main test runner HTML file that loads Jasmine and all test specsevents.spec.js- Tests for the liveflux_events.js moduledispatch.spec.js- Tests for the liveflux_dispatch.js modulebootstrap.spec.js- Tests for the liveflux_bootstrap.js module
Running Tests
Method 1: Direct Browser Access
- Open
runner.htmlin your web browser - The tests will run automatically and display results
Method 2: Local Server (Recommended)
-
Start a local HTTP server in this directory:
# Using Python python -m http.server 8000 # Using Node.js (if you have http-server installed) npx http-server -p 8000 # Using Go go run . -
Navigate to
http://localhost:8000/runner.htmlin your browser
Method 3: Live Server in VS Code
- Install the "Live Server" extension
- Right-click on
runner.htmland select "Open with Live Server"
Test Coverage
Events Module (events.spec.js)
- Event listener registration and cleanup
- Event dispatching to listeners and DOM
- Component-specific event handling
- Subscription functionality
Dispatch Module (dispatch.spec.js)
dispatchTo()- Target specific componentsdispatchToKind()- Target all components by kinddispatchToKindAndId()- Target specific component by kind and ID- Error handling for missing parameters
- Event payload construction with targeting data
Bootstrap Module (bootstrap.spec.js)
- Initialization process and state management
- Event listener setup (click, submit)
- Component placeholder mounting
- Wire initialization (async)
- Compatibility with Livewire events
- DOM ready state handling
- Error handling for missing dependencies
Writing New Tests
- Create a new
.spec.jsfile following the naming convention - Add the script reference to
runner.htmlbefore the closing body tag - Use Jasmine syntax (
describe,it,expect,spyOn, etc.) - Mock external dependencies (DOM, window.liveflux namespace)
- Clean up after each test with
beforeEachandafterEach
Mocking Strategy
The test suite uses a comprehensive mocking strategy:
- DOM APIs: Mock
document.addEventListener,querySelectorAll, etc. - Liveflux Namespace: Mock
window.livefluxwith required properties - External Dependencies: Mock functions that depend on other modules
- Component Elements: Mock DOM elements with
getAttributemethods
Debugging Tests
- Use browser developer tools to inspect test failures
- Add
console.logstatements in test specs for debugging - Use
debugger;statements to set breakpoints - Check the Jasmine HTML reporter for detailed error messages
Continuous Integration
These tests can be integrated into CI/CD pipelines using headless browsers:
# Using Chrome headless
google-chrome --headless --disable-gpu --run-all-tests runner.html
# Using Firefox headless
firefox --headless runner.html
Documentation
¶
There is no documentation for this package.
Click to show internal directories.
Click to hide internal directories.