Testing
Exercise the whole flow without charging anyone.
Use a test key
Every pk_test_ key shows a Test mode badge and every purchase reports testMode: true in the onComplete sale. Whether a card is charged does not depend on the key: only test products (set up on a test agency) use Stripe test mode. A pk_test_ key linked to an agent that sells live products takes real payments. Link your test key to an agent with test products; their 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(api_…id) andamountTotalCents(cents, not dollars). -
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://embed.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 '@cargolabs/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.
Test keys need allowed origins like live keys. Add your dev server's origin (for example http://localhost:3000) and, for CI, the origin your tests load the page from.
Going live
Create a live key with your production site in Allowed origins (required for every key), then swap the key. If the modal shows "This publishable key has no allowed origins" or your onComplete never fires, check that the page's origin (scheme, host and port) is listed exactly. 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.