Skip to main content

Testing Plugin

The testingPlugin is a built-in Coralite utility activated when the mode: 'development' configuration option is set. It is designed to assist in End-to-End (E2E) testing by providing deterministic selectors for DOM elements.

Automatic data-testid Generation #

In development mode, the testing plugin automatically duplicates all ref="xyz" attributes into data-testid attributes. Because Coralite isolates references across component instances, these data-testid properties are resolved into a strict namespace pattern.

Namespace Pattern #

The generated data-testid follows this format:

text
Code copied!
[componentId]__[refName]-[instanceIndex]

Example:

HTML
Code copied!
<!-- Source Component Template (my-button.html) -->
<template id="my-button">
  <button ref="btn">Click me</button>
</template>

<!-- Rendered Output (Development Mode) -->
<button ref="my-button__btn-0" data-testid="my-button__btn-0">Click me</button>

E2E Testing Usage #

When using a testing framework like Playwright, you can use these deterministic IDs to select elements even if they are deeply nested or part of multiple component instances.

JavaScript
Code copied!
  // Playwright example
  test('should click the button', async ({ page }) => {
    await page.goto('/');
    // Await hydration
    await page.evaluate(() => window.__coralite_ready__);
  
    // Select using the namespaced test ID
    await page.getByTestId('my-button__btn-0').click();
  });

Key Points #

Start Building with Coralite!

Use the scaffolding script to get jump started into your next project with Coralite

Copied commandline!