sand4rt / playwright-ct-angular

Playwright Angular component testing.
https://www.npmjs.com/package/@sand4rt/experimental-ct-angular
MIT License
48 stars 4 forks source link

ReferenceError: window is not defined #50

Closed chronospatian closed 5 months ago

chronospatian commented 5 months ago

Version: 1.41.2

I'm testing out this library and ran into this error when using beforeMount in my component test.

npm run test-ct

> web-component-harness@0.0.0 test-ct
> playwright test -c playwright-ct.config.ts

ReferenceError: window is not defined

    at node_modules/@sand4rt/experimental-ct-angular/hooks.mjs:20:1

Minimal reproduction:

import {test} from "@sand4rt/experimental-ct-angular";
import {AppComponent} from "./app.component";
import {beforeMount} from "@sand4rt/experimental-ct-angular/hooks";

test.describe('harness', () => {
  beforeMount(async ({ TestBed }) => {
    TestBed.configureTestingModule({
      imports: []
    })
  })

  test('it should work', async ({ mount }) => {
    const spec = await mount(AppComponent)
  })
})

Consider changing window to globalThis?

chronospatian commented 5 months ago

Workaround for now by adding globalThis.window = globalThis at the top of playwright-ct.config.ts

chronospatian commented 5 months ago

I missed that the beforeMount function needs to go in playwright/index.ts, not the test file. Closing.

sand4rt commented 5 months ago

@chronospatian thanks a lot for sharing your feedback