rtk: Add base to url and fix mock handler

This commit is contained in:
Ondrej Ezr 2024-07-18 12:47:57 +02:00 committed by Klara Simickova
parent 797ceddcd1
commit a1a49806e1
9 changed files with 3670 additions and 5233 deletions

View file

@ -16,9 +16,9 @@ type RequestTypes = 'GET' | 'PUT' | 'POST' | 'DELETE';
export function spyOnRequest(pathname: string, method: RequestTypes) {
return new Promise((resolve) => {
// @ts-expect-error Parameter 'name' implicitly has an 'any' type.ts(7006)
const listener = async (req) => {
if (req.url.pathname === pathname && req.method === method) {
const listener = async ({ request: req }: { request: Request }) => {
const url = new URL(req.url);
if (url.pathname === pathname && req.method === method) {
const requestData = await req.clone().json();
resolve(requestData);
// Cleanup listener after successful intercept

View file

@ -1,10 +1,10 @@
import { configure } from '@testing-library/react';
import nodeFetch, { Request, Response } from 'node-fetch';
// import nodeFetch, { Request, Response } from 'node-fetch';
import { server } from './mocks/server';
import 'vitest-canvas-mock';
Object.assign(global, { fetch: nodeFetch, Request, Response });
// Object.assign(global, { fetch: nodeFetch, Request, Response });
// scrollTo is not defined in jsdom - needed for the navigation to the wizard
window.HTMLElement.prototype.scrollTo = function () {};