-
-
Notifications
You must be signed in to change notification settings - Fork 483
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
Add dev warning when type prop is missed for checkbox, radio or multi… #204
Conversation
The |
Can you add a test? Warnings are tested like this. |
Codecov Report
@@ Coverage Diff @@
## master #204 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 9 9
Lines 173 181 +8
Branches 58 63 +5
=====================================
+ Hits 173 181 +8
Continue to review full report at Codecov.
|
This is a great PR. I wonder if this warning shouldn't be in |
@erikras I was just commenting about env check, here it goes: Each let's consider even really simple example of // input.js
const warning =
'production' === 'production'
? (condition, message) => {}
: (condition, message) => {
if (!condition) {
console.error(`Warning: ${message}`)
}
}
warning(false, 'Log') // uglifyjs input.js -c --toplevel
((condition,message)=>{})(!1,"Log"); I've also explained this lately in those 2 comments (here && here) if you want to read slightly more. My recommendation is to wrap each call site to remove all this dead code. I can do it as part of this PR or I can remove this "explicit" env check from this PR and prepare a follow up PR wrapping each call site.
Gonna look into it in a moment and ping u when I'm done with it.
I've briefly thought about it, but
Thanks! I thought you are gonna like it 😉 |
Awesome, I love being proved wrong! Makes total sense. I definitely wouldn't mind a PR converting all the other usages of |
...actually, now that I think about it, this revelation kind of renders the |
This is great! We were unable to get radios working properly with a custom component before sending in |
432ab0b
to
03f90e1
Compare
!props.type | ||
|
||
const type = targetType === 'select-multiple' ? 'select' : targetType | ||
const { value }: any = |
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.
aint sure if this is entirely correct, if not - let me know what should be changed about it
@@ -151,8 +174,7 @@ export default class Field extends React.Component<Props, State> { | |||
} else if ((rest: Object).type === 'radio') { | |||
input.checked = value === _value | |||
input.value = _value | |||
} | |||
if (component === 'select' && (rest: Object).multiple) { | |||
} else if (component === 'select' && (rest: Object).multiple) { |
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.
I think those are exclusive things, right?
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.
Hopefully no one wants a <select type="radio">
. 🤣
|
||
expect(spy).toHaveBeenCalled() | ||
expect(spy).toHaveBeenCalledTimes(3) | ||
expect(spy.mock.calls[0][0]).toBe( |
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.
I find snapshots really nice for those kind of tests ("warning" text/errors thrown snapshots), but you do not use any snapshots so I wasn't sure if you'd like this approach.
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.
I only just recently understood snapshot testing. Not actively against it, but not excited to migrate any tests that could be more concise with snapshots... 🤷♂️
@erikras provided a test, please take a look :)
Sure thing, gonna send additional PR in a minute.
It still encapsulates branching logic, not much - but might be nice to keep it. We'll discuss this under upcoming PR. |
03f90e1
to
511216b
Compare
Published in |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Simple PR improving DX by providing a helpful warning to the developer about his/her mistake.