Skip to content

Lupa API Reference / assert/semantic_dom / normalizeDom

Function: normalizeDom()

normalizeDom(html, options?): string

Defined in: src/assert/semantic_dom.ts:45

Normalizes a DOM element or HTML string into a deterministic HTML string for semantic comparison, applying all ignore rules.

Parameters

html

string | Element | DocumentFragment

The HTML string or DOM element to normalize

options?

SemanticDomOptions = {}

Optional options to control the normalization process

Returns

string

The normalized HTML string

Example

ts
const normalized = normalizeDom(document.body, {
  ignoreTextContent: true,
  ignoreAttributeValueFor: [
    {
      tags: ['*'],
      attributes: ['class', 'data-testid'],
    },
  ],
})