-
Notifications
You must be signed in to change notification settings - Fork 279
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
test(e2e): [base-select,slider,time-select,tag,icon]fix e2e test error #2408
Changes from all commits
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 |
---|---|---|
|
@@ -9,7 +9,7 @@ test('默认尺寸', async ({ page }) => { | |
const input = select.locator('.tiny-input') | ||
const tag = select.locator('.tiny-tag') | ||
|
||
await expect(input.locator('.tiny-input__inner')).toHaveCSS('height', '28px') | ||
await expect(input.locator('.tiny-input__inner')).toHaveCSS('height', '32px') | ||
await expect(tag.nth(0)).toHaveClass(/tiny-tag--light/) | ||
}) | ||
|
||
|
@@ -39,7 +39,7 @@ test('small 尺寸', async ({ page }) => { | |
|
||
await expect(input).toHaveClass(/tiny-input-small/) | ||
await expect(tag.nth(0)).toHaveClass(/tiny-tag--small tiny-tag--light/) | ||
expect(height).toBeCloseTo(32, 1) | ||
expect(height).toBeCloseTo(28, 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider adding a tolerance constant for height assertions. While using toBeCloseTo() with precision 1 is good for handling minor rendering differences, consider extracting the height values and tolerance to constants for better maintainability. +const SIZE_HEIGHTS = {
+ default: 32,
+ medium: 40,
+ small: 28,
+ mini: 27
+};
+const HEIGHT_TOLERANCE = 1;
test('small 尺寸', async ({ page }) => {
// ...
- expect(height).toBeCloseTo(28, 1)
+ expect(height).toBeCloseTo(SIZE_HEIGHTS.small, HEIGHT_TOLERANCE)
|
||
}) | ||
|
||
test('mini 尺寸', async ({ page }) => { | ||
|
@@ -54,5 +54,5 @@ test('mini 尺寸', async ({ page }) => { | |
|
||
await expect(input).toHaveClass(/tiny-input-mini/) | ||
await expect(tag.nth(0)).toHaveClass(/tiny-tag--mini tiny-tag--light/) | ||
expect(height).toBeCloseTo(24, 1) | ||
expect(height).toBeCloseTo(27, 1) | ||
}) |
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -6,11 +6,12 @@ test('快捷键', async ({ page }) => { | |||||||||||||
const slider = page.locator('.tiny-slider-container .tiny-slider') | ||||||||||||||
const sliderBlock = slider.locator('.tiny-slider__handle') | ||||||||||||||
// 鼠标按下滑块 | ||||||||||||||
await sliderBlock.hover() | ||||||||||||||
await page.mouse.down() | ||||||||||||||
await sliderBlock.click() | ||||||||||||||
// 快捷键左键向左移动 | ||||||||||||||
await page.keyboard.press('ArrowLeft') | ||||||||||||||
await page.waitForTimeout(50) | ||||||||||||||
await page.keyboard.press('ArrowLeft') | ||||||||||||||
await page.waitForTimeout(50) | ||||||||||||||
Comment on lines
+12
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider using waitForChanges instead of fixed timeouts. While adding timeouts helps with race conditions, fixed delays can make tests brittle and slower than necessary. Consider waiting for actual state changes instead. - await page.waitForTimeout(50)
+ await expect(slider.locator('.tiny-slider__tips')).toHaveText('39')
await page.keyboard.press('ArrowLeft')
- await page.waitForTimeout(50)
+ await expect(slider.locator('.tiny-slider__tips')).toHaveText('38') This approach:
📝 Committable suggestion
Suggested change
|
||||||||||||||
await sliderBlock.hover() | ||||||||||||||
await expect(slider.locator('.tiny-slider__tips')).toHaveText('38') | ||||||||||||||
|
||||||||||||||
|
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.
Test coverage has been significantly reduced.
The current changes remove crucial functionality testing (copy-paste verification) in favor of a simple visibility check. While this may temporarily fix the failing test, it no longer validates the core copy functionality.
Consider these alternatives: