Skip to content

UIEvent.view is always null #709

Description

@creage
  • @testing-library/user-event version: 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 microsoft/fluentui#19233.

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

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions