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