diff --git a/packages/react/lib/TextField/index.test.js b/packages/react/lib/TextField/index.test.js index 804910ce9..787a6b3f9 100644 --- a/packages/react/lib/TextField/index.test.js +++ b/packages/react/lib/TextField/index.test.js @@ -31,6 +31,45 @@ describe('', () => { unmount(); }); + it('should return number if type is number', async () => { + const onChangeMock = jest.fn(); + const user = userEvent.setup(); + const { unmount, container } = render( + + ); + + const input = container.querySelector('input'); + await user.type(input, '3'); + await blur(input); + + expect(onChangeMock).toHaveBeenCalledWith( + expect.objectContaining({ value: 3 }) + ); + + unmount(); + }); + + it('should be invalid if number is out of range', async () => { + const user = userEvent.setup(); + const { unmount, container } = render( + + ); + + const input = container.querySelector('input'); + await user.type(input, '-1'); + await blur(input); + + expect(container).toMatchSnapshot(); + + unmount(); + }); it('should allow to be used with a FieldControl', async () => { const user = userEvent.setup(); @@ -126,4 +165,5 @@ describe('', () => { expect(container).toMatchSnapshot('always focused'); unmount(); }); + }); diff --git a/packages/react/lib/TextField/index.test.js.snap b/packages/react/lib/TextField/index.test.js.snap index c159117a7..d223a462e 100644 --- a/packages/react/lib/TextField/index.test.js.snap +++ b/packages/react/lib/TextField/index.test.js.snap @@ -55,6 +55,21 @@ exports[` should allow to reset the field 2`] = ` `; +exports[` should be invalid if number is out of range 1`] = ` +
+
+ +
+
+`; + exports[` should be invalid if validation fails 1`] = `