Skip to content

Commit

Permalink
fix: disable clock tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Aug 22, 2024
1 parent c815cc4 commit f2fcdd6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 30 deletions.
57 changes: 27 additions & 30 deletions tests/api-mocking/api-mocking.spec.ts
Original file line number Diff line number Diff line change
@@ -1,73 +1,70 @@
import { test, expect, type Page } from '@playwright/test';
import { test, expect, type Page } from "@playwright/test";

test.describe('Mocking an API call', () => {

test('mocks a fruit and does not call api', async ({ page }) => {
test.describe("Mocking an API call", () => {
test("mocks a fruit and does not call api", async ({ page }) => {
// Mock the api call before navigating
await page.route('*/**/api/v1/fruits', async (route) => {
const json = [{ name: 'Strawberry', id: 21 }];
await page.route("*/**/api/v1/fruits", async (route) => {
const json = [{ name: "Strawberry", id: 21 }];
await route.fulfill({ json });
});
// Go to the page
await page.goto('https://demo.playwright.dev/api-mocking');
await page.goto("https://demo.playwright.dev/api-mocking");

// Assert that the Strawberry fruit is visible
await expect(page.getByText('Strawberry')).toBeVisible();
await expect(page.getByText("Strawberry")).toBeVisible();
});

});

test.describe('Intercepting the request and modifying it', () => {

test('gets the json from api and adds a new fruit', async ({ page }) => {
test.describe("Intercepting the request and modifying it", () => {
test("gets the json from api and adds a new fruit", async ({ page }) => {
// Get the response and add to it
await page.route('*/**/api/v1/fruits', async (route) => {
await page.route("*/**/api/v1/fruits", async (route) => {
const response = await route.fetch();
const json = await response.json();
json.push({ name: 'Playwright', id: 100 });
json.push({ name: "Playwright", id: 100 });
// Fulfill using the original response, while patching the response body
// with the given JSON object.
await route.fulfill({ response, json });
});

// Go to the page
await page.goto('https://demo.playwright.dev/api-mocking');
await page.goto("https://demo.playwright.dev/api-mocking");

// Assert that the new fruit is visible
await expect(page.getByText('Playwright', { exact: true })).toBeVisible();
await expect(page.getByText("Playwright", { exact: true })).toBeVisible();
});

});

test.describe('Mocking with HAR files', () => {

test('records or updates the HAR file', async ({ page }) => {
test.describe("Mocking with HAR files", () => {
test("records or updates the HAR file", async ({ page }) => {
// Get the response from the HAR file
await page.routeFromHAR('./hars/fruits.har', {
url: '*/**/api/v1/fruits',
await page.routeFromHAR("./hars/fruits.har", {
url: "*/**/api/v1/fruits",
update: true,
});

// Go to the page
await page.goto('https://demo.playwright.dev/api-mocking');
await page.goto("https://demo.playwright.dev/api-mocking");

// Assert that the Playwright fruit is visible
await expect(page.getByText('Strawberry')).toBeVisible();
await expect(page.getByText("Strawberry")).toBeVisible();
});

test('gets the json from HAR and checks the new fruit has been added', async ({ page }) => {
test("gets the json from HAR and checks the new fruit has been added", async ({
page,
}) => {
// Replay API requests from HAR.
// Either use a matching response from the HAR,
// or abort the request if nothing matches.
await page.routeFromHAR('./hars/fruits.har', {
url: '*/**/api/v1/fruits',
await page.routeFromHAR("./hars/fruits.har", {
url: "*/**/api/v1/fruits",
update: false,
});

// Go to the page
await page.goto('https://demo.playwright.dev/api-mocking');
await page.goto("https://demo.playwright.dev/api-mocking");

// Assert that the Playwright fruit is visible
await expect(page.getByText('Strawberry')).toBeVisible();
await expect(page.getByText("Strawberry")).toBeVisible();
});
});
File renamed without changes.

0 comments on commit f2fcdd6

Please sign in to comment.