-
Notifications
You must be signed in to change notification settings - Fork 5k
feat(toHaveCss) Overload toHaveCSS matcher to accept React.CSSProperties #38617
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
Changes from 2 commits
8dc86d7
02b8374
1cc6b7b
fada6c3
d34714e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1749,6 +1749,30 @@ CSS property value. | |
| ### option: LocatorAssertions.toHaveCSS.timeout = %%-csharp-java-python-assertions-timeout-%% | ||
| * since: v1.18 | ||
|
|
||
| ## async method: LocatorAssertions.toHaveCSS#2 | ||
| * since: v1.20 | ||
|
||
|
|
||
| Ensures the [Locator] resolves to an element with the given computed CSS properties. | ||
|
|
||
| **Usage** | ||
|
|
||
| ```js | ||
| const locator = page.getByRole('button'); | ||
| await expect(locator).toHaveCSS({ | ||
| display: 'flex', | ||
| backgroundColor: 'rgb(255, 0, 0)' | ||
| }); | ||
| ``` | ||
|
|
||
| ### param: LocatorAssertions.toHaveCSS#2.styles | ||
| * since: v1.58 | ||
| - `styles` <[CSSProperties]> | ||
|
|
||
| CSS properties object. | ||
|
|
||
| ### option: LocatorAssertions.toHaveCSS#2.timeout = %%-js-assertions-timeout-%% | ||
| * since: v1.58 | ||
|
|
||
| ## async method: LocatorAssertions.toHaveId | ||
| * since: v1.20 | ||
| * langs: | ||
|
|
||
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /** | ||
| * Copyright (c) Microsoft Corporation. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { expect, test } from '@playwright/test'; | ||
| import { toKebabCase } from '../../../packages/playwright-core/src/utils/isomorphic/stringUtils'; | ||
|
|
||
| test.describe('toKebabCase', () => { | ||
| test('should convert to kebab case', () => { | ||
| expect(toKebabCase('')).toBe(''); | ||
| expect(toKebabCase('display')).toBe('display'); | ||
| expect(toKebabCase('backgroundColor')).toBe('background-color'); | ||
| expect(toKebabCase('--customColor')).toBe('--custom-color'); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,11 @@ | |
| import type { APIRequestContext, Browser, BrowserContext, BrowserContextOptions, Page, LaunchOptions, ViewportSize, Geolocation, HTTPCredentials, Locator, APIResponse, PageScreenshotOptions } from 'playwright-core'; | ||
| export * from 'playwright-core'; | ||
|
|
||
| // @ts-ignore this will be any if react is not installed | ||
| type ReactCSSProperties = import('react').CSSProperties; | ||
| type FallbackCSSProperties = { [name: string]: string | number | undefined }; | ||
|
||
| export type CSSProperties = keyof ReactCSSProperties extends string ? ReactCSSProperties : FallbackCSSProperties; | ||
|
|
||
| export type BlobReporterOptions = { outputDir?: string, fileName?: string }; | ||
| export type ListReporterOptions = { printSteps?: boolean }; | ||
| export type JUnitReporterOptions = { outputFile?: string, stripANSIControlSequences?: boolean, includeProjectInTestName?: boolean }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to add #1 to the existing toHaveCSS declaration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I had originally left the original implementation as the base method without the #1 from referring to how toHaveAttribute is implemented.
I updated the referring documentation to point to #1.