question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Calling input.blur() fails if input was focused

See original GitHub issue

Basic 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:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
Rich-Harriscommented, Jan 26, 2019

(Should have added: this works in v12, just not in v13.)

0reactions
diegohazcommented, Mar 12, 2019

Jest didn’t update jsdom. That’s why I was using jest-environment-jsdom-thirteen.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found