Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

459
Views
How to tell Jest that spaces are in fact, spaces?

Given the code:

import { getLocale } from './locale';

export const euro = (priceData: number): string => {
  const priceFormatter = new Intl.NumberFormat(getLocale(), {
    style: 'currency',
    currency: 'EUR',
  });

  return priceFormatter.format(priceData);
}

export default null;

and the related test:

import { euro } from './currency';

test('euro', () => {
  expect(euro(42)).toBe("42,00 €");
});

Jest says:

Screenshot of Jest complaining that the string are not equal even though both are seemingly the same string. Error is on the space in between number and currency produced by the Intl component.

Even if I copy-paste the expected result of Jest to my assert, the error is still the same.

So the question is: Why the hell? :-D

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You want this test to assert:

"42,00\xa0€"

It's not a space (different ascii code / unicode). According to a jest issue about string comparison being incorrect Intl.NumberFormat uses a non-breaking space.

And as pointed out in a similar question's answer:

NumberFormat use small non-breaking space (\u202f) for thousand separator and normal non-breaking space beforece currency (\xa0).

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!