Skip to content

Narrow down test to get rid of anything() usage

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:

  1. We use expect.objectContaining() to check if the argument passed to renderGFM is an object that contains certain properties.
  2. We specifically check for the innerHTML property of this object.
  3. We use expect.stringContaining(versionedReadmeHtml) to verify that the innerHTML includes the versionedReadmeHtml string.

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

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

Merge request reports

Loading