jest-preset-angular: ReferenceError: PointerEvent is not defined

Issue :

After upgrading to Jest 24, I get this Typescript error:

ReferenceError: PointerEvent is not defined

I use a tsconfig.spec.json (which seems to be loaded by ts-jest) which contains "lib": ["es2017", "dom"] in compilerOptions.

Expected behavior :

I expect PointerEvent to be defined, as it is part of the TypeScript dom lib.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 28

Most upvoted comments

Ok, I was able to reproduce your issue, will have a look at it.

I see often some issues about configuration and examples. Perhaps it’s good that in the example of this repo we put example projects with base configuration so one can check and follow it.

@lonix1 I tried with a newly generated nx-workspace and an app inside and it worked flawlessly for me. Maybe you can generate a new project with nx and compare to that.

npx create-nx-workspace newworkspace
cd newworkspace
ng g application testapp
ng test testapp

For this example I always pressed <enter> in prompts to get started with defaults. Jest will also be picked as default test framework.

The tests in apps/testapp/src/app/app.component.spec.ts ran through and I also had access to DOM types.

I created a simple Angular project and added jest without problems. You can check it out here: https://github.com/wtho/jest-angular-example

A dom-type depending test was added in app.component.spec.ts.

I described the commands I ran to set it up in the README.md.

I later also modified the project configuration according to @dirkluijk’s configs, and it still worked.

Versions:

node v11.12.0
jest 24.5.0
ts-jest 24.0.0
jest-preset-angular 7.0.1
typescript 3.2.4

I cannot find any obvious misconfiguration, maybe you can find something.

Yes my config looks the same, and I have similar problem