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

Types resolution fails for expect-puppeteer matchers #598

Closed
mulekick opened this issue Oct 7, 2024 · 4 comments
Closed

Types resolution fails for expect-puppeteer matchers #598

mulekick opened this issue Oct 7, 2024 · 4 comments

Comments

@mulekick
Copy link
Contributor

mulekick commented Oct 7, 2024

🐛 Bug Report

When writing tests with Typescript, the types resolution fails in the VSCode IDE (and maybe other code editors as well) for the jest-puppeteer globals :

  • expect
  • browser
  • context
  • page
  • puppeteerConfig
  • jestPuppeteer

To Reproduce

Steps to reproduce the behavior:

  1. Follow the installation procedure detailed in the "Getting started" section of jest-puppeteer README.
  2. Create a *.test.ts file and write some basic tests involving jest-puppeteer globals.
  3. Types resolution fails : Typescript flags globals as not found and expect-puppeteer matchers as nonexistent.
  4. Types resolution for globals can be enabled by adding :
import "jest-puppeteer";
import {expect} from "expect-puppeteer";
  1. At this stage, expect-puppeteer matchers are nevertheless still flagged as nonexistent by Typescript.

Expected behavior

Types resolution should work, globals and expect-puppeteer matchers should be available in the IDE for autocompletion and autocorrect.

Link to repl or repo (highly encouraged)

Repo here

Run npx envinfo --system --binaries --npmPackages expect-puppeteer,jest-dev-server,jest-environment-puppeteer,jest-puppeteer,spawnd --markdown --clipboard

Paste the results here:

## System:
 - OS: Linux 6.1 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
 - CPU: (6) x64 Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
 - Memory: 369.64 MB / 2.85 GB
 - Container: Yes
 - Shell: 5.2.15 - /bin/bash
## Binaries:
 - Node: 20.17.0 - ~/.nvm/versions/node/v20.17.0/bin/node
 - npm: 10.8.3 - ~/.nvm/versions/node/v20.17.0/bin/npm
## npmPackages:
 - expect-puppeteer: 10.1.1 => 10.1.1 
 - jest-environment-puppeteer: 10.1.1 => 10.1.1 
 - jest-puppeteer: 10.1.1 => 10.1.1 
@gregberge
Copy link
Member

Fixed in #599

@jamesgpearce
Copy link

I'm still seeing this type error with a fresh NPM install.

image

What might I be doing wrong?

System:

  • OS: macOS 14.5
  • CPU: (8) arm64 Apple M2
  • Memory: 147.27 MB / 16.00 GB
  • Shell: 5.9 - /bin/zsh

Binaries:

  • Node: 22.8.0 - /opt/homebrew/bin/node
  • npm: 10.9.0 - /opt/homebrew/bin/npm
  • pnpm: 9.1.4 - /opt/homebrew/bin/pnpm
  • bun: 1.1.28 - ~/.bun/bin/bun

npmPackages:

  • jest-puppeteer: ^10.1.2 => 10.1.2

@mulekick
Copy link
Contributor Author

This error happens if you're trying to call toMatchElement() with an argument that's not a Page | Frame | ElementHandle, which is strange because typescript flags it as a Page in your screenshot. Maybe there's a conflict with another jest based library ?

It would be great if I could clone a repo where the error occurs to see if I can reproduce it and investigate. Also, double check that you've done everything as regards to the troubleshooting section.

@mulekick
Copy link
Contributor Author

@jamesgpearce I created a pull request in your repo to fix that 👍 maybe I'll update the docs here to be more explicit about the imports thing since 10.1.2 is in fact a breaking change from the DX point of view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants