Skip to content

Conversation

@iumehara
Copy link

References #35113

  • Overload toHaveCSS to take styles property (React.CSSProperties) type.
  • Extend Matchers interface in overrides-test.d.ts to include new signature


CSS property value.

### param: LocatorAssertions.toHaveCSS.styles
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to update value parameter's type to accept React.CSSProperties rather than add a new parameter.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What makes this a little awkward is that this feature requires less parameters than before. ie. one parameter for the pojo CSS Properties, as opposed to the two parameters for the name and the value.

The current PR handles multiple possible inputs for the first argument (either the name string, or the React.CSSProperties), albeit with some questionable naming.

Should I just delete the overload signatures, and use the main function definition that has union parameters?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I was not clear. What I meant is you can use function overload with #1 and #2 suffixes. See ## method: TestInfo.fixme#1 for example. Then first overload will stay as is and the second one will have CSSProperty as the only parameter. Then in the documentation we'd have 2 entries, one per overload (see e.g. https://playwright.dev/docs/api/class-testinfo#test-info-fixme-1), you'd need to make sure that there is proper usage section that presents both signatures. Support of overloaded methods is a bit messy in our API, but CSSPropery is not much different than other overloads, so it should work.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. I kept the existing implementation untouched as the base method, and added the new method definition as #2. This way, the other documentation that references toHaveCSS can remain unchanged.

A couple questions:

  1. I did not add any usage related to non-JS APIs. Is that okay? Given the new CSSProperties parameter type, I wasn't sure how to translate them to different languages.

  2. I set since to v1.58. Is that right?

import type { TestStepInfoImpl } from '../worker/testInfo';
import type { APIResponse, Locator, Frame, Page } from 'playwright-core';
import type { FrameExpectParams } from 'playwright-core/lib/client/types';
import type { CSSProperties } from 'react';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't afford a dependency on 'react'. Can you make it work in a best effort fashion similar to what we do for Electron types today? Basically, if the user has 'react' in their project, strong typecheck would apply. Otherwise accepted type should be string only.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a type that uses 'react' only if it is imported correctly. If not, it uses a fallback type that has string keys.

Does this look okay? Also, is this the correct place to define this. I originally defined/exported this from matchers.ts, but had trouble getting the import paths to resolve.

@github-actions
Copy link
Contributor

Test results for "tests 1"

32 failed
❌ [installation tests] › playwright-test-plugin.spec.ts:34 › npm: @playwright/test plugin should work @package-installations-ubuntu-latest
❌ [installation tests] › playwright-test-plugin.spec.ts:48 › pnpm: @playwright/test plugin should work @package-installations-ubuntu-latest
❌ [installation tests] › playwright-test-plugin.spec.ts:62 › yarn: @playwright/test plugin should work @package-installations-ubuntu-latest
❌ [installation tests] › typescript-types.spec.ts:18 › typescript types should work @package-installations-ubuntu-latest
❌ [installation tests] › playwright-test-plugin.spec.ts:34 › npm: @playwright/test plugin should work @package-installations-windows-latest
❌ [installation tests] › playwright-test-plugin.spec.ts:48 › pnpm: @playwright/test plugin should work @package-installations-windows-latest
❌ [installation tests] › playwright-test-plugin.spec.ts:62 › yarn: @playwright/test plugin should work @package-installations-windows-latest
❌ [installation tests] › typescript-types.spec.ts:18 › typescript types should work @package-installations-windows-latest
❌ [installation tests] › playwright-test-plugin.spec.ts:34 › npm: @playwright/test plugin should work @package-installations-macos-latest
❌ [installation tests] › playwright-test-plugin.spec.ts:48 › pnpm: @playwright/test plugin should work @package-installations-macos-latest
❌ [installation tests] › playwright-test-plugin.spec.ts:62 › yarn: @playwright/test plugin should work @package-installations-macos-latest
❌ [installation tests] › typescript-types.spec.ts:18 › typescript types should work @package-installations-macos-latest
❌ [chromium-page] › page/expect-misc.spec.ts:522 › toHaveCSS › pass with React.CSSPProperties @ubuntu-22.04-chromium-tip-of-tree
❌ [chromium-page] › page/expect-misc.spec.ts:528 › toHaveCSS › pass with React.CSSPProperties that are camelCase @ubuntu-22.04-chromium-tip-of-tree
❌ [chromium-page] › page/expect-misc.spec.ts:534 › toHaveCSS › vendor React.CSSPProperties that are vendor-prefixed properties @ubuntu-22.04-chromium-tip-of-tree
❌ [chromium-page] › page/expect-misc.spec.ts:522 › toHaveCSS › pass with React.CSSPProperties @chromium-ubuntu-22.04-node24
❌ [chromium-page] › page/expect-misc.spec.ts:528 › toHaveCSS › pass with React.CSSPProperties that are camelCase @chromium-ubuntu-22.04-node24
❌ [chromium-page] › page/expect-misc.spec.ts:534 › toHaveCSS › vendor React.CSSPProperties that are vendor-prefixed properties @chromium-ubuntu-22.04-node24
❌ [chromium-page] › page/expect-misc.spec.ts:522 › toHaveCSS › pass with React.CSSPProperties @chromium-ubuntu-22.04-node20
❌ [chromium-page] › page/expect-misc.spec.ts:528 › toHaveCSS › pass with React.CSSPProperties that are camelCase @chromium-ubuntu-22.04-node20
❌ [chromium-page] › page/expect-misc.spec.ts:534 › toHaveCSS › vendor React.CSSPProperties that are vendor-prefixed properties @chromium-ubuntu-22.04-node20
❌ [chromium-page] › page/expect-misc.spec.ts:522 › toHaveCSS › pass with React.CSSPProperties @chromium-ubuntu-22.04-node22
❌ [chromium-page] › page/expect-misc.spec.ts:528 › toHaveCSS › pass with React.CSSPProperties that are camelCase @chromium-ubuntu-22.04-node22
❌ [chromium-page] › page/expect-misc.spec.ts:534 › toHaveCSS › vendor React.CSSPProperties that are vendor-prefixed properties @chromium-ubuntu-22.04-node22
❌ [firefox-page] › page/expect-misc.spec.ts:522 › toHaveCSS › pass with React.CSSPProperties @firefox-ubuntu-22.04-node20
❌ [firefox-page] › page/expect-misc.spec.ts:528 › toHaveCSS › pass with React.CSSPProperties that are camelCase @firefox-ubuntu-22.04-node20
❌ [firefox-page] › page/expect-misc.spec.ts:534 › toHaveCSS › vendor React.CSSPProperties that are vendor-prefixed properties @firefox-ubuntu-22.04-node20
❌ [webkit-page] › page/expect-misc.spec.ts:522 › toHaveCSS › pass with React.CSSPProperties @webkit-ubuntu-22.04-node20
❌ [webkit-page] › page/expect-misc.spec.ts:528 › toHaveCSS › pass with React.CSSPProperties that are camelCase @webkit-ubuntu-22.04-node20
❌ [webkit-page] › page/expect-misc.spec.ts:534 › toHaveCSS › vendor React.CSSPProperties that are vendor-prefixed properties @webkit-ubuntu-22.04-node20
❌ [playwright-test] › playwright.spec.ts:877 › page.pause() should disable test timeout @macos-latest-node20-1
❌ [playwright-test] › runner.spec.ts:124 › should ignore subprocess creation error because of SIGINT @macos-latest-node20-2

2 flaky ⚠️ [firefox-library] › library/inspector/cli-codegen-1.spec.ts:1082 › cli codegen › should not throw csp directive violation errors `@firefox-ubuntu-22.04-node20`
⚠️ [playwright-test] › ui-mode-trace.spec.ts:426 › should work behind reverse proxy `@macos-latest-node20-2`

34369 passed, 688 skipped


Merge workflow run.

- revert existing method definition to be the base definition. Add definition#2 that takes CSSProperties
- Define CSSProperties type that is React.CSSProperties if react is installed. If not, defaults to an object with string keys
@iumehara iumehara force-pushed the 35113-toHaveCSS-reactCSS-overload branch from 2d3bb1a to 02b8374 Compare January 4, 2026 05:36
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

Successfully merging this pull request may close these issues.

2 participants