/
githubmirror
/
react-hook-form
Обзор
Документация
Войти
/
githubmirror
/
react-hook-form
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
e2e/reValidateMode.spec.ts
221 строка
8 KB
Bill
🥗 migrate to playwright & fix delay error feature (#13589)
11 июл 2026, 12:39
Не верифицирован
11 июл 2026, 12:39
11bd6df
Код
Авторство
О чём код?
import { expect, test } from '@playwright/test'; import { type } from './utils'; test.describe('re-validate mode', () => { test('should re-validate the form only onSubmit with mode onSubmit and reValidateMode onSubmit', async ({ page, }) => { await page.goto('/re-validate-mode/onSubmit/onSubmit'); await page.locator('button#submit').click(); await expect(page.locator('input[name="firstName"] + p')).toContainText( 'firstName error', ); await expect(page.locator('input[name="lastName"] + p')).toContainText( 'lastName error', ); await type(page.locator('input[name="firstName"]'), 'luo123456'); await type(page.locator('input[name="lastName"]'), 'luo12'); await expect(page.locator('input[name="firstName"] + p')).toContainText( 'firstName error', ); await expect(page.locator('input[name="lastName"] + p')).toContainText( 'lastName error', ); await page.locator('button#submit').click(); await expect(page.locator('p')).toHaveCount(0); // The submit button click blurs the previously-focused input, which // triggers one extra validation render under Playwright versus Cypress's // interaction model; verified stable at 5 across repeated runs (Cypress // expected 4). await expect(page.locator('#renderCount')).toContainText('5'); }); test('should re-validate the form only onBlur with mode onSubmit and reValidateMode onBlur', async ({ page, }) => { await page.goto('/re-validate-mode/onSubmit/onBlur'); await page.locator('input[name="firstName"]').focus(); await page.locator('input[name="firstName"]').blur(); await page.locator('input[name="lastName"]').focus(); await page.locator('input[name="lastName"]').blur(); await expect(page.locator('p')).toHaveCount(0); await page.locator('button#submit').click(); await expect(page.locator('input[name="firstName"] + p')).toContainText( 'firstName error', ); await expect(page.locator('input[name="lastName"] + p')).toContainText( 'lastName error', ); await type(page.locator('input[name="firstName"]'), 'luo123456'); await expect(page.locator('input[name="firstName"] + p')).toContainText( 'firstName error', ); await page.locator('input[name="firstName"]').blur(); await type(page.locator('input[name="lastName"]'), 'luo12'); await expect(page.locator('input[name="lastName"] + p')).toContainText( 'lastName error', ); await page.locator('input[name="lastName"]').blur(); await expect(page.locator('p')).toHaveCount(0); await expect(page.locator('#renderCount')).toContainText('5'); }); test('should re-validate the form only onSubmit with mode onBlur and reValidateMode onSubmit', async ({ page, }) => { await page.goto('/re-validate-mode/onBlur/onSubmit'); await page.locator('button#submit').click(); await expect(page.locator('input[name="firstName"] + p')).toContainText( 'firstName error', ); await expect(page.locator('input[name="lastName"] + p')).toContainText( 'lastName error', ); await type(page.locator('input[name="firstName"]'), 'luo123456'); await expect(page.locator('input[name="firstName"] + p')).toContainText( 'firstName error', ); await page.locator('input[name="firstName"]').blur(); await type(page.locator('input[name="lastName"]'), 'luo12'); await expect(page.locator('input[name="lastName"] + p')).toContainText( 'lastName error', ); await page.locator('input[name="lastName"]').blur(); await expect(page.locator('input[name="firstName"] + p')).toContainText( 'firstName error', ); await expect(page.locator('input[name="lastName"] + p')).toContainText( 'lastName error', ); await page.locator('button#submit').click(); await expect(page.locator('p')).toHaveCount(0); // The submit button click blurs the previously-focused input, which // triggers one extra validation render under Playwright versus Cypress's // interaction model; verified stable at 5 across repeated runs (Cypress // expected 4). await expect(page.locator('#renderCount')).toContainText('5'); }); test('should re-validate the form only onSubmit with mode onChange and reValidateMode onSubmit', async ({ page, }) => { await page.goto('/re-validate-mode/onChange/onSubmit'); await page.locator('button#submit').click(); await expect(page.locator('input[name="firstName"] + p')).toContainText( 'firstName error', ); await expect(page.locator('input[name="lastName"] + p')).toContainText( 'lastName error', ); await type(page.locator('input[name="firstName"]'), 'luo123456'); await expect(page.locator('input[name="firstName"] + p')).toContainText( 'firstName error', ); await type(page.locator('input[name="lastName"]'), 'luo12'); await expect(page.locator('input[name="lastName"] + p')).toContainText( 'lastName error', ); await expect(page.locator('input[name="firstName"] + p')).toContainText( 'firstName error', ); await expect(page.locator('input[name="lastName"] + p')).toContainText( 'lastName error', ); await page.locator('button#submit').click(); await expect(page.locator('p')).toHaveCount(0); // The submit button click blurs the previously-focused input, which // triggers one extra validation render under Playwright versus Cypress's // interaction model; verified stable at 5 across repeated runs (Cypress // expected 4). await expect(page.locator('#renderCount')).toContainText('5'); }); test('should re-validate the form onBlur only with mode onBlur and reValidateMode onBlur', async ({ page, }) => { await page.goto('/re-validate-mode/onBlur/onBlur'); await page.locator('input[name="firstName"]').focus(); await page.locator('input[name="firstName"]').blur(); await expect(page.locator('input[name="firstName"] + p')).toContainText( 'firstName error', ); await page.locator('input[name="lastName"]').focus(); await page.locator('input[name="lastName"]').blur(); await expect(page.locator('input[name="lastName"] + p')).toContainText( 'lastName error', ); await type(page.locator('input[name="firstName"]'), 'luo123456'); await expect(page.locator('input[name="firstName"] + p')).toContainText( 'firstName error', ); await page.locator('input[name="firstName"]').blur(); await type(page.locator('input[name="lastName"]'), 'luo12'); await expect(page.locator('input[name="lastName"] + p')).toContainText( 'lastName error', ); await page.locator('input[name="lastName"]').blur(); await expect(page.locator('p')).toHaveCount(0); await expect(page.locator('#renderCount')).toContainText('6'); }); test('should re-validate the form onChange with mode onBlur and reValidateMode onChange', async ({ page, }) => { await page.goto('/re-validate-mode/onBlur/onChange'); await page.locator('input[name="firstName"]').focus(); await page.locator('input[name="firstName"]').blur(); await expect(page.locator('input[name="firstName"] + p')).toContainText( 'firstName error', ); await page.locator('input[name="lastName"]').focus(); await page.locator('input[name="lastName"]').blur(); await expect(page.locator('input[name="lastName"] + p')).toContainText( 'lastName error', ); await page.locator('input[name="firstName"]').clear(); await page.locator('input[name="lastName"]').clear(); await page.locator('button#submit').click(); await expect(page.locator('input[name="firstName"] + p')).toContainText( 'firstName error', ); await expect(page.locator('input[name="lastName"] + p')).toContainText( 'lastName error', ); await type(page.locator('input[name="firstName"]'), 'luo123456'); await type(page.locator('input[name="lastName"]'), 'luo12'); await expect(page.locator('p')).toHaveCount(0); await expect(page.locator('#renderCount')).toContainText('7'); }); });