Search code examples
javascriptunit-testingjestjs

How to test invalid input for encodeURIComponent()


How to write invalid input for encodeURIComponent()?

I browsed the documentation for encodeURIComponent. It mentions

URIError: Thrown if uriComponent contains a lone surrogate.

How to test this while writing a unit test?


Solution

  • You can try an invalid unicode symbol. Something like this: encodeURIComponent('\uDFFF');