4 Commits

Author SHA1 Message Date
Steve Kinney
eac857a010 Demonstrate Playwright 2024-10-08 17:04:08 -06:00
Steve Kinney
9ac6b6e1ef Demonstrate Mock Service Worker 2024-10-08 17:03:57 -06:00
Steve Kinney
17a5b21baa Create index.test.js.snap 2024-10-08 17:03:42 -06:00
Steve Kinney
d9679e954a Remove unused file 2024-10-08 17:02:46 -06:00
5 changed files with 26 additions and 10 deletions

View File

@@ -1,2 +1,12 @@
import { test, expect } from '@playwright/test'; import { test, expect } from '@playwright/test';
import { createServer } from 'vite';
test.beforeEach(async ({ page }) => {
await page.goto('http://localhost:5173');
});
test('it has a counter', async ({ page }) => {
const count = page.getByTestId('counter-count');
const incrementButton = page.getByRole('button', { name: /increment/i });
await incrementButton.click();
});

View File

@@ -0,0 +1,3 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`a super simple test 1`] = `"<div>wowowow</div>"`;

View File

@@ -1,5 +0,0 @@
import { it, expect } from 'vitest';
it('is a super simple test', () => {
expect(true).toBe(true);
});

View File

@@ -11,4 +11,13 @@ const createTask = (title) => ({
lastModified: new Date('02-29-2024').toISOString(), lastModified: new Date('02-29-2024').toISOString(),
}); });
export const handlers = []; export const handlers = [
http.get('/api/tasks', async () => {
return HttpResponse.json(tasks);
}),
http.post('/api/tasks', async ({ request }) => {
const { title } = await request.json();
const task = createTask(title);
return HttpResponse.json(task);
}),
];

View File

@@ -1,8 +1,7 @@
import { test, expect } from '@playwright/test'; import { test, expect } from '@playwright/test';
/** @type {import('../start-server').DevelopmentServer} */
test.beforeEach(async ({ page }) => { test.beforeEach(async ({ page }) => {
await page.goto('http://localhost:5173'); await page.goto('http://localhost:5174');
}); });
test('it should load the page', async ({ page }) => { test('it should load the page', async ({ page }) => {
@@ -16,7 +15,7 @@ test('it should add a task', async ({ page }) => {
await input.fill('Learn Playwright'); await input.fill('Learn Playwright');
await submit.click(); await submit.click();
const heading = await page.getByRole('heading', { name: 'Learn Playwright' }); const heading = page.getByRole('heading', { name: 'Learn Playwright' });
await expect(heading).toBeVisible(); await expect(heading).toBeVisible();
}); });