Skip to content

Add new matcher for interpolated strings

Nicolò Maria Mezzopera requested to merge 212283-add-custom-matcher into master

What does this MR do?

This MR adds a new jest custom matcher that allows to compare dom strings created by gl-sprintf with the template string that generates it, for example having the following markup:

const SOME_CONSTANT = s__('Scope|Remember to check the %{linkStart}docs!%{linkEnd} buddy');

<p data-testid="the-thing">
  <gl-sprintf :message="SOME_CONSTANT" >
    <template #link="{content}">
      <gl-link :href="someHref" target="_blank">
        {{ content }}
      </gl-link>
    </template>
  </gl-sprintf>
</p>

This would produce in vtu/jest a string like so (when queried with .text()):

Remember to check the
  docs!
 buddy

So running in your test:


const findTheThing = () => wrapper.find('[data-testid="the-thing"]');

//This fails
expect(findTheThing().text()).toBe(SOME_CONSTANT)

//This works
expect(findTheThing().text()).toMatchInterpolatedText(SOME_CONSTANT)

Part of #216749 (closed)

Edited by Nicolò Maria Mezzopera

Merge request reports

Loading