Jest-puppeteer: expect(page).toMatch gives matcher error - expected string but got object

Created on 29 Jan 2019  ·  4Comments  ·  Source: smooth-code/jest-puppeteer

🐛 Bug Report

Steps to reproduce the behavior:

Running this simple test -

describe('Totaljobs', () => {
    beforeAll(async () => {
        await page.goto('https://www.totaljobs.com');
    });

    it('should display "job ads" somewhere on the page', async () => {
        await expect(page).toMatch('job ads');
    });
});

with this version of jest -
package.json

{
  "name": "pj-demo",
  "version": "1.0.0",
  "description": "demo",
  "main": "totaljobs.test.js",
  "dependencies": {},
  "devDependencies": {
    "jest": "^24.0.0",
    "jest-puppeteer": "^3.9.0",
    "puppeteer": "^1.11.0"
  },
  "scripts": {
    "test": "jest"
  },
  "jest": {
    "preset": "jest-puppeteer"
  },
  "author": "",
  "license": "ISC"
}

fails with error -
FAIL ./totaljobs.test.js
Totaljobs
× should display "job ads" somewhere on the page (258ms)

● Totaljobs › should display "job ads" somewhere on the page

expect(received).toMatch(expected)

Matcher error: received value must be a string

Received has type:  object
Received has value: {"_accessibility": {"_client": [CDPSession]}, "_client": {"_callbacks": [Map], "_connection" .......

Running with an earlier version of jest works fine -
package,json

{
  "name": "pj-demo",
  "version": "1.0.0",
  "description": "demo",
  "main": "totaljobs.test.js",
  "dependencies": {},
  "devDependencies": {
    "jest": "^23.6.0",
    "jest-puppeteer": "^3.9.0",
    "puppeteer": "^1.11.0"
  },
  "scripts": {
    "test": "jest"
  },
  "jest": {
    "preset": "jest-puppeteer"
  },
  "author": "",
  "license": "ISC"
}
bug 🐛

Most helpful comment

met same error

puppeteer: 2.0.0,
jest: 24.9.0,
jest-puppeteer: 4.3.0

All 4 comments

hi, @Greg-oliver99

Thank you very much for reporting this bug.

It seems that it was caused by the Jest@24 version, and we will fix the issue related to Jest@24 as soon as possible this week.

I suggest you use [email protected] now.

hi @Greg-oliver99

jest-puppeteer are support jest v24 now.

you can use [email protected] to resolve this bug

@xiaoyuhen I met the same issue again when I switched from preset("jest-puppeteer") to custom-environment.js.

"jest": "^24.8.0",
"jest-puppeteer": "^4.2.0",
"puppeteer": "^1.17.0"

met same error

puppeteer: 2.0.0,
jest: 24.9.0,
jest-puppeteer: 4.3.0
Was this page helpful?
0 / 5 - 0 ratings

Related issues

FezVrasta picture FezVrasta  ·  4Comments

alexander-elgin picture alexander-elgin  ·  4Comments

testerez picture testerez  ·  6Comments

binhxn picture binhxn  ·  6Comments

undrafted picture undrafted  ·  4Comments