From 9aac1570d8bccfdf4584b22196cc23a479b47aff Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Wed, 5 Aug 2020 04:02:17 +0200 Subject: [PATCH] fix(fireEvent): Make sure react dispatches focus/blur events (#758) * test: Run CI with experimental React * stable -> latest * fix(fireEvent): Make sure react dispatches focus/blur events * Remove todo --- .travis.yml | 11 ++++++----- src/fire-event.js | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index c2f47b7a..eae48ee7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,14 +9,14 @@ node_js: - 14 - node env: - - REACT_NEXT=false - - REACT_NEXT=true + - REACT_DIST=latest + - REACT_DIST=next + - REACT_DIST=experimental install: - npm install # as requested by the React team :) # https://reactjs.org/blog/2019/10/22/react-release-channels.html#using-the-next-channel-for-integration-testing - - if [ "$REACT_NEXT" = true ]; then npm install react@next - react-dom@next; fi + - npm install react@$REACT_DIST react-dom@$REACT_DIST script: - npm run validate - npx codecov@3 @@ -27,7 +27,8 @@ branches: jobs: allow_failures: - - env: REACT_NEXT=true + - REACT_DIST=next + - REACT_DIST=experimental include: - stage: release node_js: 14 diff --git a/src/fire-event.js b/src/fire-event.js index 071aff8a..b4e60928 100644 --- a/src/fire-event.js +++ b/src/fire-event.js @@ -41,4 +41,18 @@ fireEvent.select = (node, init) => { fireEvent.keyUp(node, init) } +// React event system tracks native focusout/focusin events for +// running blur/focus handlers +// @link https://github.com/facebook/react/pull/19186 +const blur = fireEvent.blur +const focus = fireEvent.focus +fireEvent.blur = (...args) => { + fireEvent.focusOut(...args) + return blur(...args) +} +fireEvent.focus = (...args) => { + fireEvent.focusIn(...args) + return focus(...args) +} + export {fireEvent}