Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
flessard opened this issue Jun 4, 2021 · 3 comments

Comments

@flessard
Copy link

flessard commented Jun 4, 2021

🐛 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

@ahnpnl
Copy link
Contributor

ahnpnl commented Jun 5, 2021

Jest 27 default test environment is node, you need to switch to jsdom manually to have Event.

@SimenB
Copy link
Member

SimenB commented Jun 5, 2021

Yep 👍

@SimenB SimenB closed this as completed Jun 5, 2021
@github-actions
Copy link

github-actions bot commented Jul 6, 2021

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants