You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it.only('should format typed value',()=>{renderComponent({maximumAmount: '100'});// this is a custom method that renders an input with default valuesawaituserEvent.tripleClick(screen.getByDisplayValue('0.00'));awaituserEvent.keyboard('55.7');awaituserEvent.tab();// on blur, the component reformats its value to '55.70'expect(screen.getByDisplayValue('55.7')).toBeInTheDocument();// this works (it shouldn't)expect(screen.getByDisplayValue('55.70')).toBeInTheDocument();// this doesn't work (it should)});
What you did:
I'm testing an internally built component that's based on a DOM input. One of it's functions is to format a number according to currency after a blur. E.g. if you type '55.7' and tab out, it will change its value to '55.70'. The field is first rendered with the value '0.00'.
What happened:
The first getByDisplayValue('0.00') works, and that allows us to send events to the element.
But after we type '55.7' and tab out, neither getByDisplayValue('55.70') nor findByDisplayValue('55.70') can find the element. When they fail, here is the output:
You can see that the input has the value '55.70' as expected.
In a browser with real user events, the input properly shows '55.70'. And in this unit test, the input ends with the correct value, as you can see by the output above.
Instead, getByDisplayValue('55.7') and findByDisplayValue('55.7') both work, i.e. with the typed value instead of the re-formatted value after blur.
Reproduction:
I'm hoping there's an easy answer... 🙄
Problem description:
We can't unit test this part of our component's behavior.
Suggested solution:
Hope for the best?
The text was updated successfully, but these errors were encountered:
@testing-library/jest-dom
version: 5.16.5react
andreact-dom
version: 16.13.1jest
version: 27.0.1node
version: 14.21.1Relevant code or config:
What you did:
I'm testing an internally built component that's based on a DOM
input
. One of it's functions is to format a number according to currency after a blur. E.g. if you type '55.7' and tab out, it will change its value to '55.70'. The field is first rendered with the value '0.00'.What happened:
The first getByDisplayValue('0.00') works, and that allows us to send events to the element.
But after we type '55.7' and tab out, neither getByDisplayValue('55.70') nor findByDisplayValue('55.70') can find the element. When they fail, here is the output:
You can see that the input has the value '55.70' as expected.
In a browser with real user events, the input properly shows '55.70'. And in this unit test, the input ends with the correct value, as you can see by the output above.
Instead, getByDisplayValue('55.7') and findByDisplayValue('55.7') both work, i.e. with the typed value instead of the re-formatted value after blur.
Reproduction:
I'm hoping there's an easy answer... 🙄
Problem description:
We can't unit test this part of our component's behavior.
Suggested solution:
Hope for the best?
The text was updated successfully, but these errors were encountered: