Skip to content

Commit b5b27b8

Browse files
fix: standardize quotes and improve error messages in form submission tests
1 parent 0f676c2 commit b5b27b8

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

tests/form.spec.ts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,65 +29,69 @@
2929
// await expect(page.locator('p')).toHaveText('Submission failed. Please try again.');
3030
// });
3131

32-
import { test, expect } from '@playwright/test';
32+
import { test, expect } from "@playwright/test";
3333

34-
test.describe('Form Submission Tests', () => {
35-
test('✅ Form submission works correctly', async ({ page }) => {
36-
await page.goto('/form');
34+
test.describe("Form Submission Tests", () => {
35+
test("✅ Form submission works correctly", async ({ page }) => {
36+
await page.goto("/form");
3737

3838
// Check form elements exist
3939
await expect(page.locator('input[name="name"]')).toBeVisible();
4040
await expect(page.locator('input[name="email"]')).toBeVisible();
41-
await expect(page.locator('button[type="submit"]')).toHaveText('Submit');
41+
await expect(page.locator('button[type="submit"]')).toHaveText("Submit");
4242

4343
// Fill out the form
44-
await page.fill('input[name="name"]', 'John Doe');
45-
await page.fill('input[name="email"]', '[email protected]');
44+
await page.fill('input[name="name"]', "John Doe");
45+
await page.fill('input[name="email"]', "[email protected]");
4646

4747
// Submit the form
4848
await page.click('button[type="submit"]');
4949

5050
// Expect success message
51-
await expect(page.locator('#message')).toHaveText(`Hello John Doe, your form has been submitted successfully!`);
51+
await expect(page.locator("#message")).toHaveText(
52+
`Hello John Doe, your form has been submitted successfully!`
53+
);
5254
});
5355

54-
test('❌ Shows validation error if fields are missing', async ({ page }) => {
55-
await page.goto('/form');
56+
test("❌ Shows validation error if fields are missing", async ({ page }) => {
57+
await page.goto("/form");
5658

5759
// Click submit without filling anything
5860
await page.click('button[type="submit"]');
5961

6062
// Expect validation error
61-
await expect(page.locator('#error')).toHaveText('Both Name and Email are required');
63+
await expect(page.locator("#error")).toHaveText(
64+
"Both Name and Email are required"
65+
);
6266
});
6367

64-
test('❌ Shows validation error for invalid email', async ({ page }) => {
65-
await page.goto('/form');
68+
test("❌ Shows validation error for invalid email", async ({ page }) => {
69+
await page.goto("/form");
6670

6771
// Fill in the name field
68-
await page.fill('input[name="name"]', 'John Doe');
72+
await page.fill('input[name="name"]', "John Doe");
6973
// Enter an invalid email
70-
await page.fill('input[name="email"]', 'invalid-email');
74+
await page.fill('input[name="email"]', "invalid-email");
7175

7276
// Submit the form
7377
await page.click('button[type="submit"]');
7478

7579
// Expect email validation error
76-
await expect(page.locator('#error')).toHaveText('Invalid email format');
80+
await expect(page.locator("#error")).toHaveText("Invalid email formats");
7781
});
7882

79-
test('🔄 Reset button clears the form', async ({ page }) => {
80-
await page.goto('/form');
83+
test("🔄 Reset button clears the form", async ({ page }) => {
84+
await page.goto("/form");
8185

8286
// Fill out the form
83-
await page.fill('input[name="name"]', 'John Doe');
84-
await page.fill('input[name="email"]', '[email protected]');
87+
await page.fill('input[name="name"]', "John Doe");
88+
await page.fill('input[name="email"]', "[email protected]");
8589

8690
// Click reset
8791
await page.click('button[type="button"]');
8892

8993
// Expect fields to be cleared
90-
await expect(page.locator('input[name="name"]')).toHaveValue('');
91-
await expect(page.locator('input[name="email"]')).toHaveValue('');
94+
await expect(page.locator('input[name="name"]')).toHaveValue("");
95+
await expect(page.locator('input[name="email"]')).toHaveValue("");
9296
});
9397
});

0 commit comments

Comments
 (0)