Skip to content

Can't use Event in setup file Cause ReferenceError: Event is not defined, Jest 27 #11528

Closed
@flessard

Description

@flessard

🐛 Bug Report

In my project i use setupFilesAfterEnv to provide a file for mocking the AnimationEvent. In jest 26 this setup file work without any error. Bu if i upgrade to jest 27, all my test fails with errors ReferenceError: Event is not defined

This is my setup file :

global.AnimationEvent = class AnimationEvent extends Event
  implements AnimationEvent {
  private _animationName: string;
  private _elapsedTime: number;
  private _pseudoElement: string;

  constructor(type: string, animationEventInitDict: AnimationEventInit = {}) {
    const {
      animationName = "",
      elapsedTime = 0,
      pseudoElement = "",
      ...eventInitDict
    } = animationEventInitDict;
    super(type, eventInitDict);

    this._animationName = animationName;
    this._elapsedTime = elapsedTime;
    this._pseudoElement = pseudoElement;
  }

  get animationName() {
    return this._animationName;
  }

  get elapsedTime() {
    return this._elapsedTime;
  }

  get pseudoElement() {
    return this._pseudoElement;
  }
};

I try to find what change in change log or any breaking change about this, but I found nothing.

envinfo

System:
    OS: macOS 11.4
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
  Binaries:
    Node: 12.14.1 - /usr/local/bin/node
    Yarn: 1.21.1 - /usr/local/bin/yarn
    npm: 6.13.4 - /usr/local/bin/npm

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions