Skip to content

Commit 7dc9d2d

Browse files
test(textarea): migrate to toHaveScreenshot (#28087)
Issue number: N/A --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> Several tests for this component are still using Playwright's old `toMatchSnapshot` assertion. It's now recommended to use the newer `toHaveScreenshot` assertion. This new assertion reduces the size of each screenshot and brings anti-flake improvements such as disabling animations by default. We previously migrated most of our codebase to use `toHaveScreenshot`, but it looks like we missed the tests that were written during the development of Ionic 7 in a separate branch off `main`. ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - Migrate component tests to use `toHaveScreenshot`. Note: There should be no layout changes to any of the screenshots. The only difference between the old and new screenshots should be image and file size. ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change, please describe the impact and migration path for existing applications below. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> --------- Co-authored-by: ionitron <[email protected]>
1 parent c8d214a commit 7dc9d2d

File tree

309 files changed

+71
-77
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

309 files changed

+71
-77
lines changed

core/src/components/textarea/test/bottom-content/textarea.e2e.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
5353
);
5454

5555
const errorText = page.locator('ion-textarea .error-text');
56-
expect(await errorText.screenshot()).toMatchSnapshot(screenshot(`textarea-error-custom-color`));
56+
await expect(errorText).toHaveScreenshot(screenshot(`textarea-error-custom-color`));
5757
});
5858
});
5959
test.describe('textarea: hint text rendering', () => {
@@ -62,7 +62,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
6262
await page.setContent(`<ion-textarea helper-text="my helper" label="my textarea"></ion-textarea>`, config);
6363

6464
const bottomEl = page.locator('ion-textarea .textarea-bottom');
65-
expect(await bottomEl.screenshot()).toMatchSnapshot(screenshot(`textarea-bottom-content-helper`));
65+
await expect(bottomEl).toHaveScreenshot(screenshot(`textarea-bottom-content-helper`));
6666
});
6767
test('should not have visual regressions when rendering error text', async ({ page }) => {
6868
await page.setContent(
@@ -71,7 +71,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
7171
);
7272

7373
const bottomEl = page.locator('ion-textarea .textarea-bottom');
74-
expect(await bottomEl.screenshot()).toMatchSnapshot(screenshot(`textarea-bottom-content-error`));
74+
await expect(bottomEl).toHaveScreenshot(screenshot(`textarea-bottom-content-error`));
7575
});
7676
});
7777
});
@@ -137,7 +137,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
137137
);
138138

139139
const bottomEl = page.locator('ion-textarea .textarea-bottom');
140-
expect(await bottomEl.screenshot()).toMatchSnapshot(screenshot(`textarea-bottom-content-counter`));
140+
await expect(bottomEl).toHaveScreenshot(screenshot(`textarea-bottom-content-counter`));
141141
});
142142

143143
test('should not have visual regressions when rendering counter with helper text', async ({ page }) => {
@@ -147,9 +147,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
147147
);
148148

149149
const bottomEl = page.locator('ion-textarea .textarea-bottom');
150-
expect(await bottomEl.screenshot()).toMatchSnapshot(
151-
screenshot(`textarea-bottom-content-counter-helper-text`)
152-
);
150+
await expect(bottomEl).toHaveScreenshot(screenshot(`textarea-bottom-content-counter-helper-text`));
153151
});
154152

155153
test('should not have visual regressions when rendering counter with error text', async ({ page }) => {
@@ -159,7 +157,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
159157
);
160158

161159
const bottomEl = page.locator('ion-textarea .textarea-bottom');
162-
expect(await bottomEl.screenshot()).toMatchSnapshot(screenshot(`textarea-bottom-content-counter-error-text`));
160+
await expect(bottomEl).toHaveScreenshot(screenshot(`textarea-bottom-content-counter-error-text`));
163161
});
164162
});
165163
});

core/src/components/textarea/test/card/textarea.e2e.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
1818
);
1919

2020
const card = page.locator('ion-card');
21-
expect(await card.screenshot()).toMatchSnapshot(screenshot(`textarea-card`));
21+
await expect(card).toHaveScreenshot(screenshot(`textarea-card`));
2222
});
2323
});
2424
});

core/src/components/textarea/test/color/textarea.e2e.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
2323
);
2424

2525
const textarea = page.locator('ion-textarea');
26-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-no-fill-color-start`));
26+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-no-fill-color-start`));
2727
});
2828
test('should set label and highlight color on focus with end label placement', async ({ page }) => {
2929
await page.setContent(
@@ -34,7 +34,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
3434
);
3535

3636
const textarea = page.locator('ion-textarea');
37-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-no-fill-color-end`));
37+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-no-fill-color-end`));
3838
});
3939
test('should set label and highlight color on focus with fixed label placement', async ({ page }) => {
4040
await page.setContent(
@@ -45,7 +45,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
4545
);
4646

4747
const textarea = page.locator('ion-textarea');
48-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-no-fill-color-fixed`));
48+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-no-fill-color-fixed`));
4949
});
5050
test('should set label and highlight color on focus with floating label placement', async ({ page }) => {
5151
await page.setContent(
@@ -56,7 +56,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
5656
);
5757

5858
const textarea = page.locator('ion-textarea');
59-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-no-fill-color-floating`));
59+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-no-fill-color-floating`));
6060
});
6161
test('should set label and highlight color on focus with stacked label placement', async ({ page }) => {
6262
await page.setContent(
@@ -67,7 +67,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
6767
);
6868

6969
const textarea = page.locator('ion-textarea');
70-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-no-fill-color-stacked`));
70+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-no-fill-color-stacked`));
7171
});
7272
});
7373
test.describe('textarea: fill solid', () => {
@@ -80,7 +80,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
8080
);
8181

8282
const textarea = page.locator('ion-textarea');
83-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-solid-color-start`));
83+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-solid-color-start`));
8484
});
8585
test('should set label and highlight color on focus with end label placement', async ({ page }) => {
8686
await page.setContent(
@@ -91,7 +91,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
9191
);
9292

9393
const textarea = page.locator('ion-textarea');
94-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-solid-color-end`));
94+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-solid-color-end`));
9595
});
9696
test('should set label and highlight color on focus with fixed label placement', async ({ page }) => {
9797
await page.setContent(
@@ -102,7 +102,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
102102
);
103103

104104
const textarea = page.locator('ion-textarea');
105-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-solid-color-fixed`));
105+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-solid-color-fixed`));
106106
});
107107
test('should set label and highlight color on focus with floating label placement', async ({ page }) => {
108108
await page.setContent(
@@ -113,7 +113,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
113113
);
114114

115115
const textarea = page.locator('ion-textarea');
116-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-solid-color-floating`));
116+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-solid-color-floating`));
117117
});
118118
test('should set label and highlight color on focus with stacked label placement', async ({ page }) => {
119119
await page.setContent(
@@ -124,7 +124,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
124124
);
125125

126126
const textarea = page.locator('ion-textarea');
127-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-solid-color-stacked`));
127+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-solid-color-stacked`));
128128
});
129129
});
130130
test.describe('textarea: fill outline', () => {
@@ -137,7 +137,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
137137
);
138138

139139
const textarea = page.locator('ion-textarea');
140-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-outline-color-start`));
140+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-outline-color-start`));
141141
});
142142
test('should set label and highlight color on focus with end label placement', async ({ page }) => {
143143
await page.setContent(
@@ -148,7 +148,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
148148
);
149149

150150
const textarea = page.locator('ion-textarea');
151-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-outline-color-end`));
151+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-outline-color-end`));
152152
});
153153
test('should set label and highlight color on focus with fixed label placement', async ({ page }) => {
154154
await page.setContent(
@@ -159,7 +159,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
159159
);
160160

161161
const textarea = page.locator('ion-textarea');
162-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-outline-color-fixed`));
162+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-outline-color-fixed`));
163163
});
164164
test('should set label and highlight color on focus with floating label placement', async ({ page }) => {
165165
await page.setContent(
@@ -170,7 +170,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
170170
);
171171

172172
const textarea = page.locator('ion-textarea');
173-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-outline-color-floating`));
173+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-outline-color-floating`));
174174
});
175175
test('should set label and highlight color on focus with stacked label placement', async ({ page }) => {
176176
await page.setContent(
@@ -181,7 +181,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
181181
);
182182

183183
const textarea = page.locator('ion-textarea');
184-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-outline-color-stacked`));
184+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-outline-color-stacked`));
185185
});
186186
});
187187
});

core/src/components/textarea/test/fill/textarea.e2e.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ configs({ modes: ['md'] }).forEach(({ title, screenshot, config }) => {
2323
);
2424

2525
const textarea = page.locator('ion-textarea');
26-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-fill-solid`));
26+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-fill-solid`));
2727
});
2828
test('should render correctly with floating label', async ({ page }) => {
2929
await page.setContent(
@@ -42,7 +42,7 @@ configs({ modes: ['md'] }).forEach(({ title, screenshot, config }) => {
4242
);
4343

4444
const textarea = page.locator('ion-textarea');
45-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-fill-solid-label-floating`));
45+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-fill-solid-label-floating`));
4646
});
4747
test('should not have visual regressions with shaped solid', async ({ page }) => {
4848
await page.setContent(
@@ -61,7 +61,7 @@ configs({ modes: ['md'] }).forEach(({ title, screenshot, config }) => {
6161
);
6262

6363
const textarea = page.locator('ion-textarea');
64-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-fill-shaped-solid`));
64+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-fill-shaped-solid`));
6565
});
6666
test('padding and border radius should be customizable', async ({ page }) => {
6767
await page.setContent(
@@ -89,7 +89,7 @@ configs({ modes: ['md'] }).forEach(({ title, screenshot, config }) => {
8989
);
9090

9191
const textarea = page.locator('ion-textarea');
92-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-fill-shaped-solid-custom`));
92+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-fill-shaped-solid-custom`));
9393
});
9494
});
9595
test.describe('textarea: fill outline', () => {
@@ -109,7 +109,7 @@ configs({ modes: ['md'] }).forEach(({ title, screenshot, config }) => {
109109
);
110110

111111
const textarea = page.locator('ion-textarea');
112-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-fill-outline`));
112+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-fill-outline`));
113113
});
114114
test('should render correctly with floating label', async ({ page }) => {
115115
await page.setContent(
@@ -128,7 +128,7 @@ configs({ modes: ['md'] }).forEach(({ title, screenshot, config }) => {
128128
);
129129

130130
const textarea = page.locator('ion-textarea');
131-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-fill-outline-label-floating`));
131+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-fill-outline-label-floating`));
132132
});
133133
test('should not have visual regressions with shaped outline', async ({ page }) => {
134134
await page.setContent(
@@ -147,7 +147,7 @@ configs({ modes: ['md'] }).forEach(({ title, screenshot, config }) => {
147147
);
148148

149149
const textarea = page.locator('ion-textarea');
150-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-fill-shaped-outline`));
150+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-fill-shaped-outline`));
151151
});
152152
test('padding and border radius should be customizable', async ({ page }) => {
153153
await page.setContent(
@@ -175,7 +175,7 @@ configs({ modes: ['md'] }).forEach(({ title, screenshot, config }) => {
175175
);
176176

177177
const textarea = page.locator('ion-textarea');
178-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-fill-shaped-outline-custom`));
178+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-fill-shaped-outline-custom`));
179179
});
180180
});
181181
});
@@ -219,7 +219,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
219219
);
220220

221221
const textarea = page.locator('ion-textarea');
222-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-fill-outline-slotted-label`));
222+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-fill-outline-slotted-label`));
223223
});
224224
test('should render the notch correctly with a slotted label after the textarea was originally hidden', async ({
225225
page,
@@ -247,7 +247,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
247247

248248
await textarea.evaluate((el: HTMLIonSelectElement) => el.style.removeProperty('display'));
249249

250-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-fill-outline-hidden-slotted-label`));
250+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-fill-outline-hidden-slotted-label`));
251251
});
252252
});
253253
});

core/src/components/textarea/test/highlight/textarea.e2e.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
2424
);
2525

2626
const textarea = page.locator('ion-textarea');
27-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-no-fill-valid`));
27+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-no-fill-valid`));
2828
});
2929
test('should render invalid state correctly', async ({ page }) => {
3030
await page.setContent(
@@ -43,7 +43,7 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
4343
);
4444

4545
const textarea = page.locator('ion-textarea');
46-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-no-fill-invalid`));
46+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-no-fill-invalid`));
4747
});
4848
test('should render focused state correctly', async ({ page }) => {
4949
await page.setContent(
@@ -62,7 +62,7 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
6262
);
6363

6464
const textarea = page.locator('ion-textarea');
65-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-no-fill-focus`));
65+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-no-fill-focus`));
6666
});
6767
});
6868
test.describe('textarea: solid', () => {
@@ -84,7 +84,7 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
8484
);
8585

8686
const textarea = page.locator('ion-textarea');
87-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-solid-valid`));
87+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-solid-valid`));
8888
});
8989
test('should render invalid state correctly', async ({ page }) => {
9090
await page.setContent(
@@ -104,7 +104,7 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
104104
);
105105

106106
const textarea = page.locator('ion-textarea');
107-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-solid-invalid`));
107+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-solid-invalid`));
108108
});
109109
test('should render focused state correctly', async ({ page }) => {
110110
await page.setContent(
@@ -124,7 +124,7 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
124124
);
125125

126126
const textarea = page.locator('ion-textarea');
127-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-solid-focus`));
127+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-solid-focus`));
128128
});
129129
});
130130
test.describe('textarea: outline', () => {
@@ -146,7 +146,7 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
146146
);
147147

148148
const textarea = page.locator('ion-textarea');
149-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-outline-valid`));
149+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-outline-valid`));
150150
});
151151
test('should render invalid state correctly', async ({ page }) => {
152152
await page.setContent(
@@ -166,7 +166,7 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
166166
);
167167

168168
const textarea = page.locator('ion-textarea');
169-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-outline-invalid`));
169+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-outline-invalid`));
170170
});
171171
test('should render focused state correctly', async ({ page }) => {
172172
await page.setContent(
@@ -186,7 +186,7 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
186186
);
187187

188188
const textarea = page.locator('ion-textarea');
189-
expect(await textarea.screenshot()).toMatchSnapshot(screenshot(`textarea-outline-focus`));
189+
await expect(textarea).toHaveScreenshot(screenshot(`textarea-outline-focus`));
190190
});
191191
});
192192
});

0 commit comments

Comments
 (0)