So I have a React application and I wanted to test the formatting of my input, and I couldn't test it properly, because payment uses qt, and qt uses the which property of the KeyboardEvent which is deprecated (the recommendation being that we should use the key event instead). And apperently jest, who (to my knowledge) uses js-dom to render the components in the document, doesn't seem to be creating the which property in the KeyboardEvent.
I first thought about opening this issue on js-dom, but since this is a deprecated property I just figured they had moved on from using it and it won't come back to it. Then I thought about opening this issue on qt, but as the readme says this is a dependency used primarily by this library, and my problem being with this library, I decided to open it here instead.
Of course, that is only the case if this is really the problem, in my tests we receive every time from the which property on the KeyboardEvent a value of 0.
To make the test I'm using:
the test is more or less:
import React, { useEffect, useRef } from 'react';
import Payment from 'payment';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
test('test', () => {
function Fake() {
const container = useRef(null);
useEffect(() => {
Payment.formatCardCVC(container.current.querySelector('input'));
}, []);
return (
<div ref={container}>
<input type="text" />
</div>
);
}
render(<Fake />);
userEvent.type(screen.getByRole('textbox'), 'invalid!');
expect(screen.getByRole('textbox')).toHaveValue('');
});
So I have a React application and I wanted to test the formatting of my input, and I couldn't test it properly, because
paymentusesqt, andqtuses thewhichproperty of the KeyboardEvent which is deprecated (the recommendation being that we should use thekeyevent instead). And apperently jest, who (to my knowledge) usesjs-domto render the components in the document, doesn't seem to be creating thewhichproperty in the KeyboardEvent.I first thought about opening this issue on js-dom, but since this is a deprecated property I just figured they had moved on from using it and it won't come back to it. Then I thought about opening this issue on
qt, but as the readme says this is a dependency used primarily by this library, and my problem being with this library, I decided to open it here instead.Of course, that is only the case if this is really the problem, in my tests we receive every time from the
whichproperty on theKeyboardEventa value of0.To make the test I'm using:
the test is more or less: