Skip to content

Commit

Permalink
fix: replace expect(generic) with expect(value) (#1109)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgozman authored Jul 28, 2023
1 parent a089da8 commit c655391
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 60 deletions.
2 changes: 1 addition & 1 deletion dotnet/docs/api/class-apiresponseassertions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Makes the assertion check for the opposite condition. For example, this code tes
**Usage**

```csharp
Expect(ApiResponse).Not
Expect(Response).Not
```

**Type**
Expand Down
2 changes: 1 addition & 1 deletion dotnet/docs/release-notes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ This version was also tested against the following stable channels:
- [Expect(Locator).ToHaveTextAsync()](/api/class-locatorassertions.mdx#locator-assertions-to-have-text) now pierces open shadow roots.
- New option `Editable` for [Expect(Locator).ToBeEditableAsync()](/api/class-locatorassertions.mdx#locator-assertions-to-be-editable).
- New option `Visible` for [Expect(Locator).ToBeVisibleAsync()](/api/class-locatorassertions.mdx#locator-assertions-to-be-visible).
- [Expect(ApiResponse).ToBeOKAsync()](/api/class-apiresponseassertions.mdx#api-response-assertions-to-be-ok) is now available.
- [Expect(Response).ToBeOKAsync()](/api/class-apiresponseassertions.mdx#api-response-assertions-to-be-ok) is now available.
### Other highlights
- New option `MaxRedirects` for [ApiRequestContext.GetAsync()](/api/class-apirequestcontext.mdx#api-request-context-get) and others to limit redirect count.
Expand Down
2 changes: 1 addition & 1 deletion dotnet/docs/test-assertions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import HTMLCard from '@site/src/components/HTMLCard';
| [Expect(Locator).ToHaveValuesAsync()](/api/class-locatorassertions.mdx#locator-assertions-to-have-values) | Select has options selected |
| [Expect(Page).ToHaveTitleAsync()](/api/class-pageassertions.mdx#page-assertions-to-have-title) | Page has a title |
| [Expect(Page).ToHaveURLAsync()](/api/class-pageassertions.mdx#page-assertions-to-have-url) | Page has a URL |
| [Expect(ApiResponse).ToBeOKAsync()](/api/class-apiresponseassertions.mdx#api-response-assertions-to-be-ok) | Response has an OK status |
| [Expect(Response).ToBeOKAsync()](/api/class-apiresponseassertions.mdx#api-response-assertions-to-be-ok) | Response has an OK status |


[Accessibility]: /api/class-accessibility.mdx "Accessibility"
Expand Down
2 changes: 1 addition & 1 deletion java/docs/api/class-apiresponseassertions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ assertThat(response).not().isOK();
**Usage**

```java
assertThat(apiResponse).not()
assertThat(response).not()
```

**Returns**
Expand Down
2 changes: 1 addition & 1 deletion java/docs/test-assertions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import HTMLCard from '@site/src/components/HTMLCard';
| [assertThat(locator).hasValues()](/api/class-locatorassertions.mdx#locator-assertions-to-have-values) | Select has options selected |
| [assertThat(page).hasTitle()](/api/class-pageassertions.mdx#page-assertions-to-have-title) | Page has a title |
| [assertThat(page).hasURL()](/api/class-pageassertions.mdx#page-assertions-to-have-url) | Page has a URL |
| [assertThat(apiResponse).isOK()](/api/class-apiresponseassertions.mdx#api-response-assertions-to-be-ok) | Response has an OK status |
| [assertThat(response).isOK()](/api/class-apiresponseassertions.mdx#api-response-assertions-to-be-ok) | Response has an OK status |


[APIRequest]: /api/class-apirequest.mdx "APIRequest"
Expand Down
2 changes: 1 addition & 1 deletion nodejs/docs/api/class-apiresponseassertions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ await expect(response).not.toBeOK();
**Usage**

```js
expect(apiResponse).not
expect(response).not
```

**Type**
Expand Down
20 changes: 10 additions & 10 deletions nodejs/docs/api/class-genericassertions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ expect(value.prop).toBe(1);

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.9</font><x-search>genericAssertions.toBeCloseTo</x-search>

Compares floating point numbers for approximate equality. Use this method instead of [expect(generic).toBe()](/api/class-genericassertions.mdx#generic-assertions-to-be) when comparing floating point numbers.
Compares floating point numbers for approximate equality. Use this method instead of [expect(value).toBe()](/api/class-genericassertions.mdx#generic-assertions-to-be) when comparing floating point numbers.

**Usage**

Expand Down Expand Up @@ -308,9 +308,9 @@ expect(new Set(value)).toContain(2);

Ensures that value is an `Array` or `Set` and contains an item equal to the expected.

For objects, this method recursively checks equality of all fields, rather than comparing objects by reference as performed by [expect(generic).toContain()](/api/class-genericassertions.mdx#generic-assertions-to-contain-2).
For objects, this method recursively checks equality of all fields, rather than comparing objects by reference as performed by [expect(value).toContain()](/api/class-genericassertions.mdx#generic-assertions-to-contain-2).

For primitive values, this method is equivalent to [expect(generic).toContain()](/api/class-genericassertions.mdx#generic-assertions-to-contain-2).
For primitive values, this method is equivalent to [expect(value).toContain()](/api/class-genericassertions.mdx#generic-assertions-to-contain-2).

**Usage**

Expand All @@ -337,9 +337,9 @@ expect(new Set(value)).toContainEqual({ another: 2 });

Compares contents of the value with contents of `expected`, performing "deep equality" check.

For objects, this method recursively checks equality of all fields, rather than comparing objects by reference as performed by [expect(generic).toBe()](/api/class-genericassertions.mdx#generic-assertions-to-be).
For objects, this method recursively checks equality of all fields, rather than comparing objects by reference as performed by [expect(value).toBe()](/api/class-genericassertions.mdx#generic-assertions-to-be).

For primitive values, this method is equivalent to [expect(generic).toBe()](/api/class-genericassertions.mdx#generic-assertions-to-be).
For primitive values, this method is equivalent to [expect(value).toBe()](/api/class-genericassertions.mdx#generic-assertions-to-be).

**Usage**

Expand Down Expand Up @@ -379,7 +379,7 @@ expect([1, 2, 3]).toHaveLength(3);

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.9</font><x-search>genericAssertions.toHaveProperty</x-search>

Ensures that property at provided `keyPath` exists on the object and optionally checks that property is equal to the `expected`. Equality is checked recursively, similarly to [expect(generic).toEqual()](/api/class-genericassertions.mdx#generic-assertions-to-equal).
Ensures that property at provided `keyPath` exists on the object and optionally checks that property is equal to the `expected`. Equality is checked recursively, similarly to [expect(value).toEqual()](/api/class-genericassertions.mdx#generic-assertions-to-equal).

**Usage**

Expand Down Expand Up @@ -431,7 +431,7 @@ expect(value).toMatch(/Is \d+ enough/);

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.9</font><x-search>genericAssertions.toMatchObject</x-search>

Compares contents of the value with contents of `expected`, performing "deep equality" check. Allows extra properties to be present in the value, unlike [expect(generic).toEqual()](/api/class-genericassertions.mdx#generic-assertions-to-equal), so you can check just a subset of object properties.
Compares contents of the value with contents of `expected`, performing "deep equality" check. Allows extra properties to be present in the value, unlike [expect(value).toEqual()](/api/class-genericassertions.mdx#generic-assertions-to-equal), so you can check just a subset of object properties.

When comparing arrays, the number of items must match, and each item is checked recursively.

Expand Down Expand Up @@ -462,7 +462,7 @@ expect([{ a: 1, b: 2 }]).toMatchObject([{ a: 1 }]);

Compares contents of the value with contents of `expected` **and** their types.

Differences from [expect(generic).toEqual()](/api/class-genericassertions.mdx#generic-assertions-to-equal):
Differences from [expect(value).toEqual()](/api/class-genericassertions.mdx#generic-assertions-to-equal):
* Keys with undefined properties are checked. For example, `{ a: undefined, b: 2 }` does not match `{ b: 2 }`.
* Array sparseness is checked. For example, `[, 1]` does not match `[undefined, 1]`.
* Object types are checked to be equal. For example, a class instance with fields `a` and `b` will not equal a literal object with fields `a` and `b`.
Expand Down Expand Up @@ -520,7 +520,7 @@ expect(() => {

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.9</font><x-search>genericAssertions.toThrowError</x-search>

An alias for [expect(generic).toThrow()](/api/class-genericassertions.mdx#generic-assertions-to-throw).
An alias for [expect(value).toThrow()](/api/class-genericassertions.mdx#generic-assertions-to-throw).

**Usage**

Expand Down Expand Up @@ -553,7 +553,7 @@ await expect(value).not.toBe(2);
**Usage**

```js
expect(generic).not
expect(value).not
```

**Type**
Expand Down
4 changes: 2 additions & 2 deletions nodejs/docs/api/class-testconfig.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default defineConfig({

an acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1` , unset by default.

Configuration for the [expect(snapshot).toMatchSnapshot()](/api/class-snapshotassertions.mdx#snapshot-assertions-to-match-snapshot-1) method.
Configuration for the [expect(value).toMatchSnapshot()](/api/class-snapshotassertions.mdx#snapshot-assertions-to-match-snapshot-1) method.

---

Expand Down Expand Up @@ -603,7 +603,7 @@ export default defineConfig({

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.28</font><x-search>testConfig.snapshotPathTemplate</x-search>

This option configures a template controlling location of snapshots generated by [expect(page).toHaveScreenshot()](/api/class-pageassertions.mdx#page-assertions-to-have-screenshot-1) and [expect(snapshot).toMatchSnapshot()](/api/class-snapshotassertions.mdx#snapshot-assertions-to-match-snapshot-1).
This option configures a template controlling location of snapshots generated by [expect(page).toHaveScreenshot()](/api/class-pageassertions.mdx#page-assertions-to-have-screenshot-1) and [expect(value).toMatchSnapshot()](/api/class-snapshotassertions.mdx#snapshot-assertions-to-match-snapshot-1).

**Usage**

Expand Down
4 changes: 2 additions & 2 deletions nodejs/docs/api/class-testproject.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ testProject.expect

an acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1` , unset by default.

Configuration for the [expect(snapshot).toMatchSnapshot()](/api/class-snapshotassertions.mdx#snapshot-assertions-to-match-snapshot-1) method.
Configuration for the [expect(value).toMatchSnapshot()](/api/class-snapshotassertions.mdx#snapshot-assertions-to-match-snapshot-1) method.

---

Expand Down Expand Up @@ -341,7 +341,7 @@ testProject.snapshotDir

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.28</font><x-search>testProject.snapshotPathTemplate</x-search>

This option configures a template controlling location of snapshots generated by [expect(page).toHaveScreenshot()](/api/class-pageassertions.mdx#page-assertions-to-have-screenshot-1) and [expect(snapshot).toMatchSnapshot()](/api/class-snapshotassertions.mdx#snapshot-assertions-to-match-snapshot-1).
This option configures a template controlling location of snapshots generated by [expect(page).toHaveScreenshot()](/api/class-pageassertions.mdx#page-assertions-to-have-screenshot-1) and [expect(value).toMatchSnapshot()](/api/class-snapshotassertions.mdx#snapshot-assertions-to-match-snapshot-1).

**Usage**

Expand Down
4 changes: 2 additions & 2 deletions nodejs/docs/release-notes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ This version was also tested against the following stable channels:
test('runs second', async ({ page }) => {});
```

* Use [testProject.snapshotPathTemplate](/api/class-testproject.mdx#test-project-snapshot-path-template) and [testConfig.snapshotPathTemplate](/api/class-testconfig.mdx#test-config-snapshot-path-template) to configure a template controlling location of snapshots generated by [expect(page).toHaveScreenshot()](/api/class-pageassertions.mdx#page-assertions-to-have-screenshot-1) and [expect(snapshot).toMatchSnapshot()](/api/class-snapshotassertions.mdx#snapshot-assertions-to-match-snapshot-1).
* Use [testProject.snapshotPathTemplate](/api/class-testproject.mdx#test-project-snapshot-path-template) and [testConfig.snapshotPathTemplate](/api/class-testconfig.mdx#test-config-snapshot-path-template) to configure a template controlling location of snapshots generated by [expect(page).toHaveScreenshot()](/api/class-pageassertions.mdx#page-assertions-to-have-screenshot-1) and [expect(value).toMatchSnapshot()](/api/class-snapshotassertions.mdx#snapshot-assertions-to-match-snapshot-1).

```js title="playwright.config.ts"
import { defineConfig } from '@playwright/test';
Expand Down Expand Up @@ -927,7 +927,7 @@ WebServer is now considered "ready" if request to the specified url has any of t
await expect(page).toHaveScreenshot();
```
The new [expect(page).toHaveScreenshot()](/api/class-pageassertions.mdx#page-assertions-to-have-screenshot-1) saves screenshots at the same location as [expect(snapshot).toMatchSnapshot()](/api/class-snapshotassertions.mdx#snapshot-assertions-to-match-snapshot-1).
The new [expect(page).toHaveScreenshot()](/api/class-pageassertions.mdx#page-assertions-to-have-screenshot-1) saves screenshots at the same location as [expect(value).toMatchSnapshot()](/api/class-snapshotassertions.mdx#snapshot-assertions-to-match-snapshot-1).
## Version 1.21
Expand Down
2 changes: 1 addition & 1 deletion nodejs/docs/test-assertions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ By default, the timeout for assertions is set to 5 seconds. Learn more about [va
| [expect(page).toHaveScreenshot()](/api/class-pageassertions.mdx#page-assertions-to-have-screenshot-1) | Page has a screenshot |
| [expect(page).toHaveTitle()](/api/class-pageassertions.mdx#page-assertions-to-have-title) | Page has a title |
| [expect(page).toHaveURL()](/api/class-pageassertions.mdx#page-assertions-to-have-url) | Page has a URL |
| [expect(apiResponse).toBeOK()](/api/class-apiresponseassertions.mdx#api-response-assertions-to-be-ok) | Response has an OK status |
| [expect(response).toBeOK()](/api/class-apiresponseassertions.mdx#api-response-assertions-to-be-ok) | Response has an OK status |

## Negating Matchers

Expand Down
2 changes: 1 addition & 1 deletion nodejs/docs/test-configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export default defineConfig({
| :- | :- |
| [testConfig.expect](/api/class-testconfig.mdx#test-config-expect) | [Web first assertions](./test-assertions.mdx) like `expect(locator).toHaveText()` have a separate timeout of 5 seconds by default. This is the maximum time the `expect()` should wait for the condition to be met. Learn more about [test and expect timeouts](./test-timeouts.mdx) and how to set them for a single test. |
| [expect(page).toHaveScreenshot()](/api/class-pageassertions.mdx#page-assertions-to-have-screenshot-1) | Configuration for the `expect(locator).toHaveScreeshot()` method. |
| [expect(snapshot).toMatchSnapshot()](/api/class-snapshotassertions.mdx#snapshot-assertions-to-match-snapshot-1)| Configuration for the `expect(locator).toMatchSnapshot()` method.|
| [expect(value).toMatchSnapshot()](/api/class-snapshotassertions.mdx#snapshot-assertions-to-match-snapshot-1)| Configuration for the `expect(locator).toMatchSnapshot()` method.|

### Add custom matchers using expect.extend

Expand Down
4 changes: 2 additions & 2 deletions python/docs/api/class-apiresponseassertions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ async def test_navigates_to_login_page(page: Page) -> None:

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.19</font><x-search>apiResponseAssertions.not_to_be_ok</x-search>

The opposite of [expect(api_response).to_be_ok()](/api/class-apiresponseassertions.mdx#api-response-assertions-to-be-ok).
The opposite of [expect(response).to_be_ok()](/api/class-apiresponseassertions.mdx#api-response-assertions-to-be-ok).

**Usage**

```python
expect(api_response).not_to_be_ok()
expect(response).not_to_be_ok()
```

---
Expand Down
2 changes: 1 addition & 1 deletion python/docs/test-assertions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import HTMLCard from '@site/src/components/HTMLCard';
| [expect(locator).to_have_values()](/api/class-locatorassertions.mdx#locator-assertions-to-have-values) | Select has options selected |
| [expect(page).to_have_title()](/api/class-pageassertions.mdx#page-assertions-to-have-title) | Page has a title |
| [expect(page).to_have_url()](/api/class-pageassertions.mdx#page-assertions-to-have-url) | Page has a URL |
| [expect(api_response).to_be_ok()](/api/class-apiresponseassertions.mdx#api-response-assertions-to-be-ok) | Response has an OK status |
| [expect(response).to_be_ok()](/api/class-apiresponseassertions.mdx#api-response-assertions-to-be-ok) | Response has an OK status |

## Custom Expect Message

Expand Down
12 changes: 5 additions & 7 deletions src/format_csharp.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//@ts-check

const Documentation = require('./documentation');
const { toTitleCase } = require('./generator');
const { toTitleCase, assertionArgument } = require('./generator');
/** @typedef {import('./generator').GeneratorFormatter} GeneratorFormatter */

/**
Expand All @@ -29,7 +29,7 @@ class CSharpFormatter {
}

/**
* @param {Documentation.Member} member
* @param {Documentation.Member} member
*/
formatMember(member) {
let args = [];
Expand All @@ -38,9 +38,7 @@ class CSharpFormatter {
if (member.clazz.varName === 'playwrightAssertions') {
prefix = '';
} else if (member.clazz.varName.includes('Assertions')) {
const varName = member.clazz.varName.substring(0, member.clazz.varName.length -'Assertions'.length);
// Generate `expect(locator).` instead of `locatorAssertions.`
prefix = `Expect(${toTitleCase(varName)}).`;
prefix = `Expect(${toTitleCase(assertionArgument(member.clazz))}).`;
}

let name = toTitleCase(member.alias);
Expand Down Expand Up @@ -109,7 +107,7 @@ class CSharpFormatter {
}

/**
* @param {Documentation.Type} type
* @param {Documentation.Type} type
* @param {string} direction
* @param {Documentation.Member} member
*/
Expand Down Expand Up @@ -181,7 +179,7 @@ class CSharpFormatter {
}

/**
* @param {import('./markdown').MarkdownNode} spec
* @param {import('./markdown').MarkdownNode} spec
* @returns boolean
*/
filterComment(spec) {
Expand Down
16 changes: 7 additions & 9 deletions src/format_java.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//@ts-check

const Documentation = require('./documentation');
const { toTitleCase, renderJSSignatures } = require('./generator');
const { toTitleCase, renderJSSignatures, assertionArgument } = require('./generator');
/** @typedef {import('./generator').GeneratorFormatter} GeneratorFormatter */
/** @typedef {import('./generator').FormatMode} FormatMode */

Expand All @@ -30,7 +30,7 @@ class JavaFormatter {
}

/**
* @param {Documentation.Member} member
* @param {Documentation.Member} member
*/
formatMember(member) {
let args = [];
Expand All @@ -39,10 +39,8 @@ class JavaFormatter {
if (member.clazz.varName === 'playwrightAssertions') {
prefix = '';
} else if (member.clazz.varName.includes('Assertions')) {
const varName = member.clazz.varName.substring(0, member.clazz.varName.length -'Assertions'.length);
// Generate `expect(locator).` instead of `locatorAssertions.`
prefix = `assertThat(${varName}).`;
}
prefix = `assertThat(${assertionArgument(member.clazz)}).`;
}

let name = member.alias;
if (member.kind === 'property')
Expand All @@ -52,7 +50,7 @@ class JavaFormatter {

let usages = [`${prefix}${name}`];
let link = `${prefix}${name}`;

let signatures;
if (member.kind === 'method') {
args = member.argsArray;
Expand Down Expand Up @@ -109,7 +107,7 @@ class JavaFormatter {
}

/**
* @param {Documentation.Type} type
* @param {Documentation.Type} type
* @param {string} direction
* @param {Documentation.Member} member
*/
Expand Down Expand Up @@ -176,7 +174,7 @@ class JavaFormatter {
}

/**
* @param {import('./markdown').MarkdownNode} spec
* @param {import('./markdown').MarkdownNode} spec
* @returns boolean
*/
filterComment(spec) {
Expand Down
12 changes: 5 additions & 7 deletions src/format_js.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//@ts-check

const Documentation = require('./documentation');
const { renderJSSignatures } = require('./generator');
const { renderJSSignatures, assertionArgument } = require('./generator');
/** @typedef {import('./generator').GeneratorFormatter} GeneratorFormatter */
/** @typedef {import('./markdown').MarkdownNode} MarkdownNode */
/** @typedef {import('./documentation').Member} Member */
Expand All @@ -31,7 +31,7 @@ class JavaScriptFormatter {
}

/**
* @param {Documentation.Member} member
* @param {Documentation.Member} member
*/
formatMember(member) {
let args = [];
Expand All @@ -41,10 +41,8 @@ class JavaScriptFormatter {
if (member.clazz.varName === 'playwrightAssertions') {
prefix = '';
} else if (member.clazz.varName.includes('Assertions')) {
const varName = member.clazz.varName.substring(0, member.clazz.varName.length -'Assertions'.length);
// Generate `expect(locator).` instead of `locatorAssertions.`
prefix = `expect(${varName}).`;
}
prefix = `expect(${assertionArgument(member.clazz)}).`;
}

let name = member.alias;
let usages = [`${prefix}${name}`];
Expand Down Expand Up @@ -106,7 +104,7 @@ class JavaScriptFormatter {
}

/**
* @param {MarkdownNode} spec
* @param {MarkdownNode} spec
* @returns boolean
*/
filterComment(spec) {
Expand Down
Loading

0 comments on commit c655391

Please sign in to comment.