rtk: Add base to url and fix mock handler
This commit is contained in:
parent
797ceddcd1
commit
a1a49806e1
9 changed files with 3670 additions and 5233 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 () {};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue