zombieJ
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
38 additions and
1 deletions
components/input/Input.tsx
components/input/__tests__/index.test.js
@ -20,7 +20,7 @@ function fixControlledValue<T>(value: T) {
}
function hasPrefixSuffix ( props : InputProps ) {
return 'prefix' in props || props . suffix || props . allowClear ;
return ! ! ( 'prefix' in props || props . suffix || props . allowClear ) ;
}
const InputSizes = tuple ( 'small' , 'default' , 'large' ) ;
@ -9,6 +9,16 @@ import calculateNodeHeight, { calculateNodeStyling } from '../calculateNodeHeigh
const { TextArea } = Input ;
describe ( 'Input' , ( ) => {
const errorSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
afterEach ( ( ) => {
errorSpy . mockReset ( ) ;
} ) ;
afterAll ( ( ) => {
errorSpy . mockRestore ( ) ;
} ) ;
focusTest ( Input ) ;
it ( 'should support maxLength' , ( ) => {
@ -20,6 +30,33 @@ describe('Input', () => {
const wrapper = mount ( < Input / > ) ;
wrapper . instance ( ) . select ( ) ;
} ) ;
describe ( 'focus trigger warning' , ( ) => {
it ( 'not trigger' , ( ) => {
const wrapper = mount ( < Input suffix = "bamboo" / > ) ;
wrapper
. find ( 'input' )
. instance ( )
. focus ( ) ;
wrapper . setProps ( {
suffix : 'light' ,
} ) ;
expect ( errorSpy ) . not . toBeCalled ( ) ;
} ) ;
it ( 'trigger warning' , ( ) => {
const wrapper = mount ( < Input / > ) ;
wrapper
. find ( 'input' )
. instance ( )
. focus ( ) ;
wrapper . setProps ( {
suffix : 'light' ,
} ) ;
expect ( errorSpy ) . toBeCalledWith (
'Warning: [antd: Input] When Input is focused, dynamic add or remove prefix / suffix will make it lose focus caused by dom structure change. Read more: https://ant.design/components/input/#FAQ' ,
) ;
} ) ;
} ) ;
} ) ;
focusTest ( TextArea ) ;