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]: * is not iterable when using option: true #32033

Closed
bloodgang94 opened this issue Aug 6, 2024 · 3 comments · Fixed by #32261
Closed

[Bug]: * is not iterable when using option: true #32033

bloodgang94 opened this issue Aug 6, 2024 · 3 comments · Fixed by #32261
Assignees
Labels

Comments

@bloodgang94
Copy link

bloodgang94 commented Aug 6, 2024

Note from maintainers

To provide an option that is an array of objects, use the long-form notation by wrapping the value into an array:

// Option that is an array of objects.
const optionValue = [{ key: 'value1' }, { key: 'value2' }];
test.use({
  // Wrap the value into an array and pass the scope.
  myOption: [optionValue, { scope: 'test' }],
});

Version

1.46.0

Steps to reproduce

  1. Clone repository https://github.com/bloodgang94/pw-not-iterable-reproduction-steps.git
  2. Run npm i
  3. Run tests npx playwright test

spec.ts

import { test, expect } from "@/fixtures/navigate-fixture";

test.use({ links: [{ name: "API" }, { name: "Docs" }] });

test("get started link", async ({ page }) => {
  await expect(page).toHaveURL("https://playwright.dev/docs/input");
});

fixture

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

export type NavigateFixture = {
  links: { name: string }[];
  page: Page;
};

export const test = base.extend<NavigateFixture>({
  links: [[{ name: "" }], { option: true }],
  page: async ({ page, links }, use) => {
    await page.goto("/");
    for (const link of links)
      await page
        .getByRole("link", { name: link.name })
        .press("Control+ArrowRight");
    await use(page);
  },
});

export * from "@playwright/test";

Expected behavior

Fixture code completed

Actual behavior

TypeError: links is not iterable

Additional context

There was no such problem in version 1.45.There was no such problem in version 1.45. In debugging I see that it is not an array, but an element of an array
image

Environment

OS: Win 10, 16 RAM, VS Code 1.92.0
@msilviudan
Copy link

msilviudan commented Aug 7, 2024

This bug will brake all the tests that are using arrays of objects in the fixture.

@dgozman
Copy link
Contributor

dgozman commented Aug 8, 2024

@bloodgang94 While we are figuring this out, you can do the following as a workaround:

test.use({ links: [[{ name: "API" }, { name: "Docs" }], { scope: 'test' }] });

@sergtimosh
Copy link

sergtimosh commented Sep 6, 2024

@dgozman am I right that doble array workaround passes two-dimentional array into the fixture and we need to strip it to use properly?

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

Successfully merging a pull request may close this issue.

5 participants