mxschmitt / playwright-test-coverage

Playwright Test (@playwright/test) demo to collect coverage information via Istanbul
MIT License
118 stars 16 forks source link

Getting page.evaluate Error on Angular CLI playwright project #13

Closed sh977218 closed 2 years ago

sh977218 commented 2 years ago

Hi, I'm able to generate the coverage under ./nyc_output, but I got this error in the console.

`1) [Google Chrome] › e2e-playwright/src/tests/header.coire.spec.ts:2:624 › Verify header view ====

page.evaluate: ReferenceError: cov_joa4b212j is not defined
    at eval (eval at evaluate (:192:30), <anonymous>:1:6)
    at UtilityScript.evaluate (<anonymous>:194:17)
    at UtilityScript.<anonymous> (<anonymous>:1:44)
    at Object.context [as fn] (/Users/Shi.Huang@mheducation.com/Documents/GitHub/connect-instructor-ui/e2e-playwright/lib/baseTest.ts:2:4808)`

Any idea where this error come from?

Thanks in advanced!

DPros commented 1 year ago

moving expects out of the evaluate to the chained then solved the issue:

await page.evaluate(() => return val).then(val => expect(val).toBeDefined())