UIEvent.view is always null
See original GitHub issue@testing-library/user-eventversion: 13.2.1
- Testing Framework and version: “@testing-library/react”: “12.0.0”,
- DOM Environment: “@testing-library/jest-dom”: “5.14.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:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top 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 >
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

Yeah, but we don’t use
InputEventin 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)@ph-fritsche this is not correct 😥
event.viewis supported widely, but only onUIEvent.changeevent does not inheritUIEvent, see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/change_event-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:In that place we use only
UIEvent(MouseEvent,PointerEvent,TouchEvent) soevent.viewshould work there ¯_(ツ)_/¯I have not tested yet, but this looks like a problem specific to JSDom…