Calling input.blur() fails if input was focused
See original GitHub issueBasic info:
- Node.js version: 11.6.0
- jsdom version: 13.2.0
Minimal reproduction case
const { JSDOM } = require("jsdom");
const { window } = new JSDOM();
const { document } = window;
const input = document.createElement('input');
input.focus();
input.blur();
This results in a “Cannot read property ‘_defaultView’ of undefined” error:
[project]/node_modules/jsdom/lib/jsdom/living/helpers/focusing.js:71
view: target._ownerDocument._defaultView,
^
TypeError: Cannot read property '_defaultView' of undefined
at Object.exports.fireFocusEventWithTargetAdjustment ([project]/node_modules/jsdom/lib/jsdom/living/helpers/focusing.js:71:33)
at HTMLInputElementImpl.blur ([project]/node_modules/jsdom/lib/jsdom/living/nodes/HTMLAndSVGElementShared-impl.js:52:14)
at HTMLInputElement.blur ([project]/node_modules/jsdom/lib/jsdom/living/generated/HTMLElement.js:38:23)
at Object.<anonymous> ([project]/index.js:8:7)
at Module._compile (internal/modules/cjs/loader.js:721:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:774:12)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:11 (10 by maintainers)
Top Results From Across the Web
Focusing: focus/blur - The Modern JavaScript Tutorial
blur() set/unset the focus on the element. For instance, let's make the visitor unable to leave the input if the value is invalid:....
Read more >Prevent focus to call blur functionality - Stack Overflow
Use setTimeout() to control Onblur. JSFiddle input.onblur = function() { samp.innerHTML="Called blur"; var validating = false; ...
Read more >Element: blur event - Web APIs | MDN
The blur event fires when an element has lost focus. The event does not bubble, but the related focusout event that follows does...
Read more >Focusing: focus/blur | W3docs JavaScript Tutorial
blur() methods are used for setting/unsetting the focus on the element. Let's make the user unable to leave the input, if the value...
Read more >jQuery blur() Method - W3Schools
The blur event occurs when the <input> field loses focus: ... The blur() method triggers the blur event, or attaches a function to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
(Should have added: this works in v12, just not in v13.)
Jest didn’t update jsdom. That’s why I was using
jest-environment-jsdom-thirteen
.