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.

UIEvent.view is always null

See original GitHub issue
  • @testing-library/user-event version: 13.2.1

Relevant code or config

import React from 'react';
import { FormInput } from '@fluentui/react-northstar';

import {render, screen} from '@testing-library/react';
import userEvent from '@testing-library/user-event';

test('type in form input', () => {
  render(
    <FormInput label="Test" placeholder="welcome" />
  );

  userEvent.type(screen.getByPlaceholderText('welcome'), 'hello');

  expect(screen.getByDisplayValue('hello')).toBeInTheDocument();
});

Trying to execute code above fails the test with TypeError: Cannot read property 'document' of null

According to specs the view property of UIEvent should point to the window.

This issue affects other libraries, like https://github.com/microsoft/fluentui/issues/19233.

The more generic fireEvent works fine though - the view property is defined as expected:

act(() => {
    fireEvent.change(screen.getByPlaceholderText('welcome'), { target: { value: 'hello' } });
});

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
layershiftercommented, Sep 29, 2021

The InputEvent seems to be the only UIEvent without a view property in browser. https://codesandbox.io/s/uievent-view-go6kz

Yeah, but we don’t use InputEvent in our code:

https://github.com/microsoft/fluentui/blob/586adc8eb7c4bbe3429dcb2231d713d96fc3b716/packages/fluentui/react-northstar/src/utils/whatInput.ts#L90-L108

(we use only MouseEvent, PointerEvent & TouchEvent)

1reaction
layershiftercommented, Sep 29, 2021

See https://codesandbox.io/s/eventview-njq60?file=/src/App.js . Open https://njq60.csb.app/ with different browsers. The event.view is null on input event in Chrome (Ubuntu) and Window in Firefox (Ubuntu). It is undefined on change event in both.

@ph-fritsche this is not correct 😥 event.view is supported widely, but only on UIEvent.

change event does not inherit UIEvent, see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/change_event-


Several interfaces are direct or indirect descendants of this one: MouseEvent, TouchEvent, FocusEvent, KeyboardEvent, WheelEvent, InputEvent, and CompositionEvent.

https://developer.mozilla.org/en-US/docs/Web/API/UIEvent


I modified your CodeSandbox to use keydown (https://codesandbox.io/s/event-view-forked-dn3w7?file=/src/App.js) and it works:

image

In that place we use only UIEvent (MouseEvent, PointerEvent, TouchEvent) so event.view should work there ¯_(ツ)_/¯

I have not tested yet, but this looks like a problem specific to JSDom…

Read more comments on GitHub >

github_iconTop Results From Across the Web

objective c - event touchesForView: returns null in super view
I have a subclass of UIView called BigView that overrides touchesMoved (among other things) like so: @implementation BigView - (void) ...
Read more >
UI Events - W3C
The view attribute identifies the Window from which the event was generated. The un-initialized value of this attribute MUST be null . UIEvent...
Read more >
UIEvent.sourceCapabilities - Web APIs | MDN
If no input device was responsible for the event, it returns null . When a single user interaction with an input device generates...
Read more >
hitTest(_:with:) | Apple Developer Documentation
Returns the farthest descendant of the receiver in the view hierarchy (including itself) that contains a specified point.
Read more >
iOS Responder Chain: UIResponder, UIEvent, UIControl and ...
In iOS, the Responder Chain is the name given to an UIKit-generated linked list of UIResponder objects, and is the foundation for everything ......
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