Hi commiters!
Perhaps you have encountered a problem with validating strings in Jest.
For example, the test above validates that the function receives a value and returns a rounded value.
it('It should properly format a unit value with rounding.', () => { expect(formatCurrency(1234.56, true, false)).toEqual({ measure: 'thousand', value: 'R$ 1.200,00', }); });
In this test, Jest returned an error, highlighting the differences between the expected and received values, but they are the same ?
- Expected - 1 + Received + 1 Object { "measure": "thousand", - "value": "R$ 1.200,00", + "value": "R$ 1.200,00",
The solution is to add xa0. The problem is not with your string, but how Jest compares string values ?
The corrected code is shown above.
it('It should properly format a unit value with rounding.', () => { expect(formatCurrency(1234.56, true, false)).toEqual({ measure: 'thousand', value: 'R$\xa01.200,00', // remove space and add \xa0 }); });
The above is the detailed content of Validating String in Jest. For more information, please follow other related articles on the PHP Chinese website!