This guide explains how to test the <multicorn-consent> web component locally.
- Node.js 20+
- pnpm 9+ (or npm/yarn)
cd multicorn-shield
pnpm installTest the component's functionality with Vitest:
# Run all tests once
pnpm test
# Run tests in watch mode (re-runs on file changes)
pnpm test:watch
# Run tests with coverage report
pnpm test:coverageAfter running coverage, open coverage/lcov-report/index.html in your browser to see detailed coverage.
Build the component for testing in a browser:
# Build once
pnpm build
# Build in watch mode (rebuilds on file changes)
pnpm devThis creates the dist/ folder with compiled JavaScript.
You have two options for testing in a browser:
Since the component uses ES modules, you need a local server. Here are a few options:
# Python 3
python3 -m http.server 8000
# Python 2
python -m SimpleHTTPServer 8000Then open: http://localhost:8000/examples/test-consent.html
# Install globally
npm install -g http-server
# Run in the multicorn-shield directory
http-server -p 8000Then open: http://localhost:8000/examples/test-consent.html
# Install vite globally
npm install -g vite
# Run in the multicorn-shield directory
vite --port 8000Then open: http://localhost:8000/examples/test-consent.html
If you've built the component (pnpm build), you can test with the built version:
-
Update
examples/test-consent.htmlto import fromdist:import "../dist/index.js";
-
Serve the files with any HTTP server (see Option A above)
Once you have the test page open in your browser:
- Modal Mode Test: Click "Open Modal Consent" to see the modal overlay
- Inline Mode Test: The inline consent screen is already visible below
- Toggle Permissions: Click the toggle switches or permission level buttons
- Test Events: Click "Authorize" or "Deny" and watch the event log
- Keyboard Navigation:
- Press
Tabto navigate between elements - Press
SpaceorEnterto toggle switches - Press
Escapein modal mode to deny
- Press
- Responsive: Resize your browser to test mobile (375px) layout
- ✅ Dark theme matches Shield design system
- ✅ Agent name and color display correctly
- ✅ Icons and labels are human-readable
- ✅ Spending limit shows/hides correctly
- ✅ Modal backdrop appears in modal mode
- ✅ Responsive at 375px viewport
- ✅ Toggle switches work for individual scopes
- ✅ Permission level buttons toggle correctly
- ✅ "Authorize" emits correct event (granted/partial/denied)
- ✅ "Deny" button emits consent-denied event
- ✅ Escape key denies in modal mode
- ✅ Events include correct scope data
- ✅ Tab navigation cycles through all interactive elements
- ✅ Focus trap works in modal mode
- ✅ ARIA labels are present (check with screen reader)
- ✅ Keyboard shortcuts work (Space/Enter/Escape)
Test in:
- Chrome/Edge (Chromium)
- Firefox
- Safari
- Mobile browsers (iOS Safari, Chrome Mobile)
- Make sure you're using a local HTTP server (not
file://protocol) - Check that the import path in the HTML file is correct
- Verify
pnpm buildcompleted successfully
- Check browser console for errors
- Verify Lit is installed:
pnpm list lit - Make sure the custom element is registered (check console for errors)
- Verify Shadow DOM is working (check in DevTools)
- Check that
consent-styles.tsis being imported - Look for CSS conflicts in browser DevTools
- Run
pnpm installto ensure all dependencies are installed - Check that
jsdomis installed:pnpm list jsdom - Verify Vitest config has
environment: "jsdom"
- Check the component's JSDoc comments for API details
- Review
src/consent/multicorn-consent.test.tsfor test examples - See
examples/test-consent.htmlfor usage examples