argos-ci/jest-puppeteer

How to require `expect-puppeteer` at version of `7.0.0`

caoxing9 opened this issue · 3 comments

💬 Questions and Help

Jest Puppeteer project is young, but please before asking your question:

  • Read carefully the README of the project
  • Search if your answer has already been answered in old issues

After you can submit your question and we will be happy to help you!

I use the package expect-puppeteer like this in version 6.1.0

const expect = require("expect-puppeteer").default;

async function waitForFillLoginForm(page, { username, password }) {
  const loginForm = await page.waitForSelector("#login");
  await expect(loginForm).toFill(LoginSelectors.LOGIN_USERNAME_INPUT, username);
}

But i've upgrate the version to 7.0.0 to support the lastest puppeteer, it catch an error like this

reason: expect is not a function

I try to find the reason about this, so i look over the source code, then found the way to packing has been changed to rollup,
and the export without default.

So, please give me some tips, that how can i do?

Please use v8, expect-puppeteer overload the global expect, so you don't need to import it.

Please use v8, expect-puppeteer overload the global expect, so you don't need to import it.

But my project is a node project with commonjs, how to use it in commonjs?

If it works, it's probably:

const expect = require("expect-puppeteer").expect

Or in ESM:

import {expect} from 'expect-puppeteer';

Because I'm using

	"jest": {
		"injectGlobals": false,
		"preset": "jest-puppeteer"
	},