Narrow down test to get rid of anything() usage
-
Please check this box if this contribution uses AI-generated content (including content generated by GitLab Duo features) as outlined in the GitLab DCO & CLA. As a benefit of being a GitLab Community Contributor, you receive complimentary access to GitLab Duo.
What does this MR do and why?
When implementing syntax highlighting for READMEs on the catalog page i left an expect.anything in the test.
I'm currently looking into GitLab Duo, and decided it might help me figure out how to get rid of the anything call.
This is where duo and I ended up after quite a bit of conversation:
This modification does the following:
- We use
expect.objectContaining()to check if the argument passed torenderGFMis an object that contains certain properties. - We specifically check for the
innerHTMLproperty of this object. - We use
expect.stringContaining(versionedReadmeHtml)to verify that theinnerHTMLincludes theversionedReadmeHtmlstring.
This approach allows us to verify that the correct content is being passed to renderGFM without relying on an exact match of the entire DOM tree. It checks that the HTML string we expect (stored in versionedReadmeHtml) is present in the innerHTML of the object passed to renderGFM.
References
- !170091 (merged)
- #438812 (closed)
- gitlab-org/developer-relations/contributor-success/team-task#720 (comment 2265744261)
MR acceptance checklist
It's an ai generated test improvement.
How to set up and validate locally
yarn jest spec/frontend/ci/catalog/components/details/ci_resource_readme_spec.js
Edited by Lucas Bickel