WordPress 6.9 introduces `assertEqualHTML()` on `WP_UnitTestCase`, a semantic HTML comparison method that replaces fragile `assertSame()` string comparisons in PHPUnit tests. Unlike `assertSame()`, it normalizes attribute order, class name order, style whitespace, tag capitalization, and HTML character references — so tests only fail when markup is semantically different. The post covers practical usage for testing HTML API transformations, block render callbacks, and Interactivity API directive injection, explains the tree-based failure output format, and provides migration tips for existing test suites.
Table of contents
The problem with assertSame() for HTMLWhat assertEqualHTML() doesBasic usageTesting HTML API transformationsTesting block render callbacksTesting Interactivity API directive injectionUnderstanding failure outputAdding a custom failure messageWhen to keep assertSameMigration tipsResourcesSort: