@@ -8,46 +8,68 @@ import LiteYouTube from '@site/src/components/LiteYouTube';
88
99## Version 1.39
1010
11- ### Extending expect with custom matchers
11+ ### Add custom matchers to your expect
1212
1313You can extend Playwright assertions by providing custom matchers. These matchers will be available on the expect object.
1414
15- ``` js title=fixtures.ts
15+ ``` js title="test.spec.ts"
1616import { expect as baseExpect } from ' @playwright/test' ;
1717export const expect = baseExpect .extend ({
1818 async toHaveAmount (locator : Locator , expected : number , options ?: { timeout?: number }) {
19- // Note: this matcher never passes, see the documentation for a full example.
20- // Return a "pass" flag and a message getter.
21- return { pass: false , message : () => ` Expected ${ expected} amount` };
19+ // ... see documentation for how to write matchers.
2220 },
2321});
22+
23+ test (' pass' , async ({ page }) => {
24+ await expect (page .getByTestId (' cart' )).toHaveAmount (5 );
25+ });
2426```
2527
2628See the documentation [ for a full example] ( ./test-configuration.md#add-custom-matchers-using-expectextend ) .
2729
28- ### Merging fixtures and expect matchers
30+ ### Merge test fixtures
31+
32+ You can now merge test fixtures from multiple files or modules:
33+
34+ ``` js title="fixtures.ts"
35+ import { mergeTests } from ' @playwright/test' ;
36+ import { test as dbTest } from ' database-test-utils' ;
37+ import { test as a11yTest } from ' a11y-test-utils' ;
38+
39+ export const test = mergeTests (dbTest, a11yTest);
40+ ```
41+
42+ ``` js title="test.spec.ts"
43+ import { test } from ' ./fixtures' ;
44+
45+ test (' passes' , async ({ database, page, a11y }) => {
46+ // use database and a11y fixtures.
47+ });
48+ ```
49+
50+ ### Merge custom expect matchers
2951
30- You can combine fixtures and custom expect matchers from multiple files or modules.
52+ You can now merge custom expect matchers from multiple files or modules:
3153
3254``` js title="fixtures.ts"
33- import { composedTest , composedExpect } from ' @playwright/test' ;
55+ import { mergeTests , mergeExpects } from ' @playwright/test' ;
3456import { test as dbTest , expect as dbExpect } from ' database-test-utils' ;
3557import { test as a11yTest , expect as a11yExpect } from ' a11y-test-utils' ;
3658
37- export const expect = composedExpect (dbExpect, a11yExpect );
38- export const test = composedTest (dbTest, a11yTest );
59+ export const test = mergeTests (dbTest, a11yTest );
60+ export const expect = mergeExpects (dbExpect, a11yExpect );
3961```
4062
4163``` js title="test.spec.ts"
4264import { test , expect } from ' ./fixtures' ;
4365
44- test (' passes' , async ({ database, page }) => {
66+ test (' passes' , async ({ page, database }) => {
4567 await expect (database).toHaveDatabaseUser (' admin' );
4668 await expect (page).toPassA11yAudit ();
4769});
4870```
4971
50- ### Boxed test steps
72+ ### Hide implementation details: box test steps
5173
5274You can mark a [ ` method: Test.step ` ] as "boxed" so that errors inside it point to the step call site.
5375
0 commit comments