-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(select): forward refs to select dom element
- Loading branch information
Showing
4 changed files
with
52 additions
and
24 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
__tests__/renderer/shared/components/Forms/Select/Select.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import Select from 'shared/components/Forms/Select/Select'; | ||
|
||
const mountContainer = (props = {}) => { | ||
return shallow(<Select {...props} />); | ||
}; | ||
|
||
describe('<Select />', () => { | ||
it('renders a select', () => { | ||
const children = ( | ||
<React.Fragment> | ||
<option value="foo">Foo</option> | ||
<option value="bar">Bar</option> | ||
</React.Fragment> | ||
); | ||
const props = { id: 'name', defaultValue: 'foo', children }; | ||
const wrapper = mountContainer(props); | ||
expect(wrapper.type()).toEqual('select'); | ||
expect(wrapper.props()).toEqual(expect.objectContaining(props)); | ||
}); | ||
|
||
it('applies a custom className', () => { | ||
const wrapper = mountContainer({ className: 'currency' }); | ||
expect(wrapper.prop('className').split(' ')).toContain('currency'); | ||
}); | ||
}); |
30 changes: 11 additions & 19 deletions
30
__tests__/renderer/shared/components/Forms/Select/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,20 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { mount } from 'enzyme'; | ||
|
||
import Select from 'shared/components/Forms/Select'; | ||
import SelectContainer from 'shared/components/Forms/Select'; | ||
import Select from 'shared/components/Forms/Select/Select'; | ||
|
||
const mountContainer = (props = {}) => { | ||
return shallow(<Select {...props} />); | ||
return mount(<SelectContainer {...props} />); | ||
}; | ||
|
||
describe('<Select />', () => { | ||
it('renders a select', () => { | ||
const children = ( | ||
<React.Fragment> | ||
<option value="foo">Foo</option> | ||
<option value="bar">Bar</option> | ||
</React.Fragment> | ||
); | ||
const props = { id: 'name', defaultValue: 'foo', children }; | ||
const wrapper = mountContainer(props); | ||
expect(wrapper.type()).toEqual('select'); | ||
expect(wrapper.props()).toEqual(expect.objectContaining(props)); | ||
}); | ||
|
||
it('applies a custom className', () => { | ||
const wrapper = mountContainer({ className: 'currency' }); | ||
expect(wrapper.prop('className').split(' ')).toContain('currency'); | ||
it('forwards the ref to the component', () => { | ||
const ref = React.createRef(); | ||
const wrapper = mountContainer({ ref }); | ||
console.log(wrapper.debug()); | ||
console.log(wrapper.find(Select).props()); | ||
// expect(wrapper.find(Select).prop('forwardedRef')).toBe(ref.current); | ||
// expect(wrapper.find(Select).find('input').prop('forwardedRef')).toBe(ref.current); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
export { default } from './Select'; | ||
import withForwardedRef from 'shared/hocs/withForwardedRef'; | ||
|
||
import Select from './Select'; | ||
|
||
export default withForwardedRef()(Select); |