Skip to content

Commit

Permalink
Add test coverage for CustomFileInput
Browse files Browse the repository at this point in the history
  • Loading branch information
David Ellingsworth authored and David Ellingsworth committed Apr 16, 2019
1 parent 8250ebe commit 3a4cc4e
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/__tests__/CustomInput.spec.js
Expand Up @@ -264,6 +264,45 @@ describe('Custom Inputs', () => {
expect(ref.current).not.toBeNull();
expect(ref.current).toBeInstanceOf(HTMLInputElement);
});

describe('onChange', () => {
it('calls props.onChange if it exists', () => {
const onChange = jest.fn();
const file = mount(<CustomInput type="file" onChange={onChange} />);

file.find('input').hostNodes().simulate('change');
expect(onChange).toHaveBeenCalled();
});
});

it('removes fakepath from file name', () => {
const file = mount(<CustomInput type="file" />);

file.find('input').hostNodes().simulate('change', {
target:{
value:'C:\\fakepath\\test.txt'
}
});

expect(file.find('.custom-file-label').text()).toBe('test.txt');
});

it('lists multiple files when supported', () => {
const file = mount(<CustomInput type="file" multiple/>);

file.find('input').hostNodes().simulate('change', {
target:{
value:'C:\\fakepath\\file1.txt',
files:[
{name:"file1.txt"},
{name:'file2.txt'},
{name:'file3.txt'},
]
}
})

expect(file.find('.custom-file-label').text()).toBe('file1.txt, file2.txt, file3.txt');
})
});

describe('CustomRange', () => {
Expand Down

0 comments on commit 3a4cc4e

Please sign in to comment.