-
Notifications
You must be signed in to change notification settings - Fork 419
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
Incremental PR towards #347 #462
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,33 @@ describe('NumberFormat as input', () => { | |
expect(wrapper.find('input').instance().value).toEqual('$2,456,981'); | ||
}); | ||
|
||
it('should load the default value when initial value is null', () => { | ||
const wrapper = mount(<NumberFormat value={null} defaultValue={89} />); | ||
expect(wrapper.state().value).toEqual('89'); | ||
}); | ||
|
||
it('should load the prevous valid value if the state is changed to null', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo on the statement.
|
||
class WrapperComponent extends React.Component { | ||
constructor() { | ||
super (); | ||
this.state = { | ||
testState: 90, | ||
}; | ||
} | ||
render() { | ||
return (<NumberFormat value={this.state.testState} />) | ||
} | ||
} | ||
|
||
const wrapper = mount(<WrapperComponent />); | ||
const input = wrapper.find('input'); | ||
const domInput = input.instance(); | ||
|
||
expect(domInput.value).toEqual('90'); | ||
wrapper.setState({testState: null}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This spec could be simplified you just mount Also FYI. Try avoiding interacting with states in specs. You shouldn't depend much on implementation detail. |
||
expect(domInput.value).toEqual('90'); | ||
}); | ||
|
||
it('should use defaultValue as initial value', () => { | ||
const wrapper = mount(<NumberFormat defaultValue={2456981} thousandSeparator={true} prefix={'$'} />); | ||
expect(wrapper.state().value).toEqual('$2,456,981'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should never check for state value. As it's implementation details. Instead we should test for the end side-effect.