-
Notifications
You must be signed in to change notification settings - Fork 4k
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
fix(Search): only call onBlur & onFocus event handler once #1963
fix(Search): only call onBlur & onFocus event handler once #1963
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1963 +/- ##
======================================
Coverage 99.8% 99.8%
======================================
Files 148 148
Lines 2568 2568
======================================
Hits 2563 2563
Misses 5 5
Continue to review full report at Codecov.
|
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.
@chopstikk Thanks for PR. However, I think that we should add tests there to omit such cases in future.
Something like:
describe('onFocus', () => {
it('is called with (e, data)', () => {
const onFocus = sandbox.spy()
wrapperMount(<Search onFocus={onFocus} />)
wrapper.simulate('focus')
onFocus.should.have.been.calledOnce()
onFocus.should.have.been.calledWithMatch({ }, { options })
})
})
@@ -525,6 +525,28 @@ describe('Search', () => { | |||
}) | |||
}) | |||
|
|||
describe('onBlur', () => { | |||
it('is called with (event) on search input blur', () => { | |||
const spy = sandbox.spy() |
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.
Please name spy
as event handler, i.e. onBlur
.
.simulate('blur', nativeEvent) | ||
|
||
spy.should.have.been.calledOnce() | ||
spy.should.have.been.calledWithMatch(nativeEvent) |
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.
Let's also check that second argument provides a valid props:
-wrapperMount(<Search onBlur={spy} />)
+wrapperMount(<Search onBlur={spy} results={options} />)
-spy.should.have.been.calledWithMatch(nativeEvent)
+spy.should.have.been.calledWithMatch(nativeEvent, { onBlur, results: options })
@@ -525,6 +525,28 @@ describe('Search', () => { | |||
}) | |||
}) | |||
|
|||
describe('onBlur', () => { | |||
it('is called with (event) on search input blur', () => { |
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.
Let's also correct a title is called with (e, data) on...
I love you two, thanks! 😄 |
Released in |
Fixes #1962
Search component onBlur and onFocus event handers should not be called twice.