Skip to content

Unable to resolve signature of method decorator when called as an expression. #33285

@bhargavkumar-65

Description

@bhargavkumar-65

System info
Playwright Version: [^1.32.1]
Operating System: [Windows11]
Browser: [Chromium]

During the implementing playwright step decorators into our existing tests infrastructure we faced issue with decorators.
i followed the implementation as described in below https://playwright.dev/docs/api/class-test#test-step

i see the following error

Image

import { Page,expect,test } from "@playwright/test";

function step(target: Function, context: ClassMethodDecoratorContext) {
    return function replacementMethod(...args: any) {
      const name = this.constructor.name + '.' + (context.name as string);
      return test.step(name, async () => {
        return await target.call(this, ...args);
      });
    };
  }
  
  class LoginPage {
    constructor(readonly page: Page) {}
  
    @step
    async login() {
      const account = { username: 'Alice', password: 's3cr3t' };
      await this.page.getByLabel('Username or email address').fill(account.username);
      await this.page.getByLabel('Password').fill(account.password);
      await this.page.getByRole('button', { name: 'Sign in' }).click();
      await expect(this.page.getByRole('button', { name: 'View profile and more' })).toBeVisible();
    }
  }
  
  test('example', async ({ page }) => {
    const loginPage = new LoginPage(page);
    await loginPage.login();
  });

tsconfig.json

{
    "compilerOptions": {
        "target": "ES6",
        "esModuleInterop": true,
        "module": "commonjs",
        "moduleResolution": "node",
        "lib": ["es2019", "DOM", "ES6", "DOM.Iterable", "ScriptHost"],
        "sourceMap": true,
        "declaration": true,
        "removeComments": false,
        "noImplicitAny": false,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "resolveJsonModule": true,
        "types": ["jasmine", "node"],
        "allowJs": false,
        "rootDir": "./",
        "outDir": "build-js",
        "baseUrl": ".",
        "paths": {
            "#root": ["."]
        }
    },
    "include": ["src/**/*"],
    "exclude": ["node_modules", "build-js"]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions