Skip to content

Commit

Permalink
- Add test for double rendering fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yadav committed May 14, 2023
1 parent af46317 commit 2bb335c
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion test/library/input.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useMemo } from 'react';
import React, { useState, useRef, useEffect, useMemo } from 'react';
import { renderHook } from '@testing-library/react-hooks/dom';

import TextField from 'material-ui/TextField';
Expand Down Expand Up @@ -527,6 +527,22 @@ describe('NumberFormat as input', () => {
}, 0);
});

it('should not reset the selection when manually focused on mount', async () => {
function Test() {
const localInputRef = useRef();
useEffect(() => {
// eslint-disable-next-line no-unused-expressions
localInputRef.current?.select();
}, []);

return <NumericFormat getInputRef={(elm) => (localInputRef.current = elm)} value="12345" />;
}

const { input } = await render(<Test />);
expect(input.selectionStart).toEqual(0);
expect(input.selectionEnd).toEqual(5);
});

it('should not call onFocus prop when focused then blurred in the same event loop', (done) => {
const spy = jasmine.createSpy('onFocus');
const wrapper = mount(<NumericFormat onFocus={spy} />);
Expand Down

0 comments on commit 2bb335c

Please sign in to comment.