Skip to content

Commit

Permalink
test for MagicSelect.onChange() #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Pollock committed Jul 7, 2018
1 parent 0cb13b4 commit 0e63574
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/components/fields/magic-select/MagicSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export class MagicSelect extends React.PureComponent {
/**
* Handle direct change events
*
* Probably not needed
* @param {Event} event
*/
onChange(event) {
Expand Down
30 changes: 30 additions & 0 deletions src/components/fields/magic-select/MagicSelect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,36 @@ describe('MagicSelect component', () => {
expect(updatedValue).toEqual(14);
});

it('Passes updated value, not an event ', () => {
let updatedValue = 1;
const component = mount(
<MagicSelect
id={'magic-9'}
fieldClassName={'magic'}
onValueChange={(newValue) => {
updatedValue = newValue;
}}
options={[
{
label: '1',
value: 1,
innerKey: '1'
},
{
label: '12',
value: 12,
innerKey: '12'
}
]}
value={updatedValue}
isOpen={true}
/>
);

component.instance().onChange({ target: { value: 12 } });
expect(updatedValue).toEqual(12);
});

it('Receives the updated value ', () => {
let updatedValue = 1;
const component = mount(
Expand Down

0 comments on commit 0e63574

Please sign in to comment.