Testing
Exercise the whole flow without charging anyone.
Use a test key
Every pk_test_ key opens the flow in test mode. The modal shows a Test mode badge and every purchase reports testMode: true in the onComplete sale. Payments go to Stripe test mode, so use Stripe's test cards:
| Card number | Result |
|---|---|
4242 4242 4242 4242 | Succeeds |
4000 0000 0000 9995 | Declined, insufficient funds |
4000 0025 0000 3155 | Requires 3-D Secure authentication |
Any future expiry date and any three-digit CVC work.
Checklist
- The button renders (or your own button is wired) on every page that should sell insurance.
- Clicking it opens the modal and the Test mode badge is visible.
-
onCompletefires after a test purchase and your backend records thepurchaseId. -
onClosefires when the buyer dismisses the modal, and your UI recovers. - Nothing in your
onCompletehandler treats atestMode: truesale as revenue. - The modal works on a phone-sized viewport.
- Your Content Security Policy allows
https://buy.coverport.ioinframe-srcand, if you use the script tag,https://unpkg.cominscript-src.
Automated tests
The SDK exports plain functions, so unit tests can mock the DOM:
import { mount } from '@coverport/js';
test('mount renders a button into an empty target', () => {
document.body.innerHTML = '<div id="t"></div>';
const handle = mount('#t', { key: 'pk_test_abc' });
expect(document.querySelector('#t button')?.textContent).toBe('Get insurance quote');
handle.destroy();
expect(document.querySelector('#t button')).toBeNull();
});For end-to-end tests, drive the iframe like any other cross-origin frame. In Playwright, page.frameLocator('iframe[title="CoverPort insurance quote"]') reaches the flow.
Going live
Swap the key. Then make one real purchase of your cheapest product and refund it from the CoverPort seller console, so you have seen the live path end to end.