Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Can't export extended test object (@playwright/experimental-ct-react) #30690

Closed
Thomas-Haider opened this issue May 7, 2024 · 3 comments

Comments

@Thomas-Haider
Copy link

Version

1.43.1

Steps to reproduce

create a test and past following code:

import React from 'react';
import { test as base, expect } from '@playwright/experimental-ct-react';
import { Locator, Page } from '@playwright/test';

interface BaseTestTryoutOption {
  author: string;
}
export class TodoPage {
  private readonly inputBox: Locator;
  private readonly todoItems: Locator;

  constructor(public readonly page: Page) {
    this.inputBox = this.page.locator('input.new-todo');
    this.todoItems = this.page.getByTestId('todo-item');
  }
}

export type TryoutFixture = {
  todoPage: TodoPage;
};

// typescript does not let me export the test object
export const test = base.extend<BaseTestTryoutOption & TryoutFixture>({
  author: undefined,
  todoPage: async ({ author, page, mount }, use) => {
    console.log(author);
    const todo = new TodoPage(page);
    await use(todo);
  },
});

test('basic test', async ({ page, mount }) => {
  const comp = await mount(<div data-testid={'tryout'}>hello world</div>);

  await expect(page.getByTestId('tryout')).toHaveText('hello world');
});

Expected behavior

i would expect to export the test object from the file and reuse in other test files. Check out the code reproduction code above for more details.

Actual behavior

as soon as i add the export to the test object i receive the following error:
image

Additional context

No response

Environment

System:
    OS: macOS 14.4.1
    CPU: (12) arm64 Apple M2 Max
    Memory: 4.73 GB / 64.00 GB
  Binaries:
    Node: 18.18.0 - ~/.nvm/versions/node/v18.18.0/bin/node
    Yarn: 1.22.21 - ~/.nvm/versions/node/v18.18.0/bin/yarn
    npm: 9.8.1 - ~/.nvm/versions/node/v18.18.0/bin/npm
    pnpm: 8.15.1 - ~/.nvm/versions/node/v18.18.0/bin/pnpm
  Languages:
    Bash: 3.2.57 - /bin/bash
@Thomas-Haider Thomas-Haider changed the title [Bug]: Can export extended test object (@playwright/experimental-ct-react) [Bug]: Can't export extended test object (@playwright/experimental-ct-react) May 7, 2024
@mxschmitt
Copy link
Member

I was not able to reproduce with a fresh React/Playwright CT project. Could you provide us a reproduction which we can run locally?

@Thomas-Haider
Copy link
Author

Sure, will try to find some time today or at latest i will send it on Friday :)

@mxschmitt
Copy link
Member

Closing as part of the triage process since it seemed stale. Please create a new issue with a detailed reproducible or feature request if you still face issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants