0

In Svelte component I have a tag:

<h2 data-testid="organisation">
  {@html organisation_name}
</h2>

Organisation name comes with Special Character Code, like so:

const organisation_name = 'TJ&#39;s Org 2'

I'm using Svelte @html tag so it renders as TJ's Org 2 in the browser.

The question is, how to compare it in Testing Library.

So far I've got this,

expect(getByTestId('organisation').textContent).toBe(organisation_name);

which fails and the result is obviously:

Expected: "TJ&#39;s Org 2"
Received: "TJ's Org 2"

Any idea how to convert organisation_name value in toBe method to be in readable format?

dariusz
  • 441
  • 1
  • 5
  • 17
  • Does this answer your question? [A plain JavaScript way to decode HTML entities, works on both browsers and Node](https://stackoverflow.com/questions/44195322/a-plain-javascript-way-to-decode-html-entities-works-on-both-browsers-and-node) – Ion Nov 19 '22 at 21:07

0 Answers0