Tests: Add structural assertions to JSX parser tests#341
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## trunk #341 +/- ##
============================================
+ Coverage 30.63% 30.76% +0.12%
Complexity 4410 4410
============================================
Files 291 291
Lines 36918 36918
============================================
+ Hits 11310 11357 +47
+ Misses 25608 25561 -47
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
722bb1a to
a430f3a
Compare
Adds structural assertions to jsx-parser tests that verify the parser produces correct React element output, rather than just checking existence. - jsx-parser.test.js: 35 tests with structural assertions - setup-tests.js: Extended wp/acf mocks for parser dependencies - mocks/jquery.js: DOM parsing mock using DOMParser - jest.config.js: jQuery module mapping
a430f3a to
8be93f1
Compare
What
Part of #315.
Adds structural assertions to jsx-parser tests that verify the parser produces correct React element output.
Why
PR #331 covered 10 React components in blocks-v3. For most, the mocks were sufficient to test rendered output. But jsx-parser is different: it parses HTML strings into React elements using jQuery DOM methods. The simple jQuery mock in #331 didn't support these, so tests could only verify the parser runs without errors.
This PR enhances the mock to return real DOM nodes, enabling assertions on what the parser actually produces.
How
Enhanced the jQuery mock to parse HTML using
DOMParser, enabling assertions on actual output:Testing Instructions
npm run test:unit -- tests/js/blocks-v3/ # 174 tests pass