Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TextField] False should be a valid value #4728

Merged
merged 1 commit into from
Jul 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/TextField/TextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const getStyles = (props, context, state) => {
* @returns True if the string provided is valid, false otherwise.
*/
function isValid(value) {
return Boolean(value || value === 0);
return value !== '' && value !== undefined && value !== null;
}

class TextField extends Component {
Expand Down
36 changes: 36 additions & 0 deletions src/TextField/TextField.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,40 @@ describe('<TextField />', () => {
);
});
});

describe('isValid', () => {
it('should consider the input as empty', () => {
const values = [
undefined,
null,
'',
];

values.forEach((value) => {
const wrapper = shallowWithContext(
<TextField id="isValid" value={value} />
);

assert.strictEqual(wrapper.state().hasValue, false,
`Should consider '${value}' as empty`);
});
});

it('should consider the input as not empty', () => {
const values = [
' ',
0,
false,
];

values.forEach((value) => {
const wrapper = shallowWithContext(
<TextField id="isValid" value={value} />
);

assert.strictEqual(wrapper.state().hasValue, true,
`Should consider '${value}' as not empty`);
});
});
});
});