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] Cannot pass functions or JSHandle into a component props in component testing #23435

Closed
1 task done
segevfiner opened this issue Jun 1, 2023 · 3 comments · Fixed by #23649
Closed
1 task done

Comments

@segevfiner
Copy link

System info

  • Playwright Version: v1.34.3
  • Operating System: macOS 13.4
  • Browser: Chromium
  • Other info: Vue component testing

Source code

  • I provided exact source code that allows reproducing the issue locally.

Config file

// playwright.config.ts
import { defineConfig, devices } from '@playwright/experimental-ct-vue';
import path from 'path';

/**
 * See https://playwright.dev/docs/test-configuration.
 */
export default defineConfig({
  testDir: './',
  testMatch: /.*(pw)\.(js|ts|mjs)/,
  /* The base directory, relative to the config file, for snapshot files created with toMatchSnapshot and toHaveScreenshot. */
  snapshotDir: './__snapshots__',
  /* Maximum time one test can run for. */
  timeout: 10 * 1000,
  /* Run tests in files in parallel */
  fullyParallel: true,
  /* Fail the build on CI if you accidentally left test.only in the source code. */
  forbidOnly: !!process.env.CI,
  /* Retry on CI only */
  retries: process.env.CI ? 2 : 0,
  /* Opt out of parallel tests on CI. */
  workers: process.env.CI ? 1 : undefined,
  /* Reporter to use. See https://playwright.dev/docs/test-reporters */
  reporter: 'html',
  /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
  use: {
    /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
    trace: 'on-first-retry',

    /* Port to use for Playwright component endpoint. */
    ctPort: 3100,

    ctViteConfig: {
      resolve: {
        alias: {
          '@': path.join(__dirname, './src'),
        },
      },
    },
  },

  /* Configure projects for major browsers */
  projects: [
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'] },
    },
    // {
    //   name: 'firefox',
    //   use: { ...devices['Desktop Firefox'] },
    // },
    // {
    //   name: 'webkit',
    //   use: { ...devices['Desktop Safari'] },
    // },
  ],
});

Test file (self-contained)

import { expect, test } from '@playwright/experimental-ct-vue';
import Sample from '../Sample.vue';

test('sample', async ({ page, mount }) => {
  const foo = () => 123;
  const bar = page.evaluateHandle(() => {
    return () => 123;
  });

  const component = await mount(Sample, {
    props: {
      foo,
      bar,
    },
  });
});

Steps

  • Run the test

Expected

I can pass a callback, an object containing callbacks or a JSHandle (So I can worry about the node vs browser differences myself via evaluateHandle as props.

Actual

Error: The mount function props are not JSON serializable.
@mxschmitt
Copy link
Member

This is not supported, we recommend creating a wrapper component if you need to supply custom data to your Component which you are testing.

@segevfiner
Copy link
Author

But can it be supported? At least with a JSHandle?

@mxschmitt
Copy link
Member

I'll make a feature request out of it, but there are currently no plans to do so.

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

Successfully merging a pull request may close this issue.

2 participants