@trackunit/react-test-setup 1.3.6 → 1.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs.js CHANGED
@@ -264,6 +264,98 @@ afterEach(async () => {
264
264
  react.cleanup();
265
265
  await flushPromisesInAct();
266
266
  });
267
+ const setupResponseForTanstackRouter = () => {
268
+ // Polyfill for Response global that TanStack Router v1+ requires
269
+ if (typeof globalThis.Response === "undefined") {
270
+ // Simple polyfill for Response in test environment
271
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, local-rules/no-typescript-assertion
272
+ globalThis.Response = class Response {
273
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
274
+ constructor(body, init) {
275
+ this.status = init?.status ?? 200;
276
+ this.statusText = init?.statusText ?? "";
277
+ this.headers = new Headers(init?.headers);
278
+ this.body = body;
279
+ this.ok = this.status >= 200 && this.status < 300;
280
+ this.redirected = false;
281
+ this.type = "default";
282
+ this.url = "";
283
+ }
284
+ static redirect(url, status = 302) {
285
+ return new Response(null, { status, headers: { Location: url } });
286
+ }
287
+ static error() {
288
+ return new Response(null, { status: 0 });
289
+ }
290
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
291
+ static json(data, init) {
292
+ return new Response(JSON.stringify(data), {
293
+ ...init,
294
+ headers: {
295
+ "Content-Type": "application/json",
296
+ ...init?.headers,
297
+ },
298
+ });
299
+ }
300
+ clone() {
301
+ return new Response(this.body, {
302
+ status: this.status,
303
+ statusText: this.statusText,
304
+ headers: this.headers,
305
+ });
306
+ }
307
+ };
308
+ }
309
+ if (typeof globalThis.Headers === "undefined") {
310
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, local-rules/no-typescript-assertion
311
+ globalThis.Headers = class Headers {
312
+ constructor(init) {
313
+ this.map = new Map();
314
+ if (init) {
315
+ if (Array.isArray(init)) {
316
+ init.forEach(([key, value]) => this.set(key, value));
317
+ }
318
+ else if (init instanceof Headers) {
319
+ init.forEach((value, key) => this.set(key, value));
320
+ }
321
+ else {
322
+ Object.entries(init).forEach(([key, value]) => this.set(key, value));
323
+ }
324
+ }
325
+ }
326
+ append(name, value) {
327
+ this.map.set(name.toLowerCase(), value);
328
+ }
329
+ delete(name) {
330
+ this.map.delete(name.toLowerCase());
331
+ }
332
+ get(name) {
333
+ return this.map.get(name.toLowerCase()) || null;
334
+ }
335
+ has(name) {
336
+ return this.map.has(name.toLowerCase());
337
+ }
338
+ set(name, value) {
339
+ this.map.set(name.toLowerCase(), value);
340
+ }
341
+ forEach(callback) {
342
+ this.map.forEach((value, key) => callback(value, key, this));
343
+ }
344
+ entries() {
345
+ return this.map.entries();
346
+ }
347
+ keys() {
348
+ return this.map.keys();
349
+ }
350
+ values() {
351
+ return this.map.values();
352
+ }
353
+ [Symbol.iterator]() {
354
+ return this.map.entries();
355
+ }
356
+ };
357
+ }
358
+ };
267
359
  /**
268
360
  * Sets up React Testing Library and Okta authentication mocks for testing.
269
361
  *
@@ -315,6 +407,7 @@ const setupReactTestingLibrary = () => {
315
407
  idToken: mockedIdToken,
316
408
  isAuthenticated: true,
317
409
  };
410
+ setupResponseForTanstackRouter();
318
411
  const mockedOktaAuth = () => {
319
412
  return {
320
413
  oktaAuth: {
package/index.esm.js CHANGED
@@ -243,6 +243,98 @@ afterEach(async () => {
243
243
  cleanup();
244
244
  await flushPromisesInAct();
245
245
  });
246
+ const setupResponseForTanstackRouter = () => {
247
+ // Polyfill for Response global that TanStack Router v1+ requires
248
+ if (typeof globalThis.Response === "undefined") {
249
+ // Simple polyfill for Response in test environment
250
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, local-rules/no-typescript-assertion
251
+ globalThis.Response = class Response {
252
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
253
+ constructor(body, init) {
254
+ this.status = init?.status ?? 200;
255
+ this.statusText = init?.statusText ?? "";
256
+ this.headers = new Headers(init?.headers);
257
+ this.body = body;
258
+ this.ok = this.status >= 200 && this.status < 300;
259
+ this.redirected = false;
260
+ this.type = "default";
261
+ this.url = "";
262
+ }
263
+ static redirect(url, status = 302) {
264
+ return new Response(null, { status, headers: { Location: url } });
265
+ }
266
+ static error() {
267
+ return new Response(null, { status: 0 });
268
+ }
269
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
270
+ static json(data, init) {
271
+ return new Response(JSON.stringify(data), {
272
+ ...init,
273
+ headers: {
274
+ "Content-Type": "application/json",
275
+ ...init?.headers,
276
+ },
277
+ });
278
+ }
279
+ clone() {
280
+ return new Response(this.body, {
281
+ status: this.status,
282
+ statusText: this.statusText,
283
+ headers: this.headers,
284
+ });
285
+ }
286
+ };
287
+ }
288
+ if (typeof globalThis.Headers === "undefined") {
289
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, local-rules/no-typescript-assertion
290
+ globalThis.Headers = class Headers {
291
+ constructor(init) {
292
+ this.map = new Map();
293
+ if (init) {
294
+ if (Array.isArray(init)) {
295
+ init.forEach(([key, value]) => this.set(key, value));
296
+ }
297
+ else if (init instanceof Headers) {
298
+ init.forEach((value, key) => this.set(key, value));
299
+ }
300
+ else {
301
+ Object.entries(init).forEach(([key, value]) => this.set(key, value));
302
+ }
303
+ }
304
+ }
305
+ append(name, value) {
306
+ this.map.set(name.toLowerCase(), value);
307
+ }
308
+ delete(name) {
309
+ this.map.delete(name.toLowerCase());
310
+ }
311
+ get(name) {
312
+ return this.map.get(name.toLowerCase()) || null;
313
+ }
314
+ has(name) {
315
+ return this.map.has(name.toLowerCase());
316
+ }
317
+ set(name, value) {
318
+ this.map.set(name.toLowerCase(), value);
319
+ }
320
+ forEach(callback) {
321
+ this.map.forEach((value, key) => callback(value, key, this));
322
+ }
323
+ entries() {
324
+ return this.map.entries();
325
+ }
326
+ keys() {
327
+ return this.map.keys();
328
+ }
329
+ values() {
330
+ return this.map.values();
331
+ }
332
+ [Symbol.iterator]() {
333
+ return this.map.entries();
334
+ }
335
+ };
336
+ }
337
+ };
246
338
  /**
247
339
  * Sets up React Testing Library and Okta authentication mocks for testing.
248
340
  *
@@ -294,6 +386,7 @@ const setupReactTestingLibrary = () => {
294
386
  idToken: mockedIdToken,
295
387
  isAuthenticated: true,
296
388
  };
389
+ setupResponseForTanstackRouter();
297
390
  const mockedOktaAuth = () => {
298
391
  return {
299
392
  oktaAuth: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@trackunit/react-test-setup",
3
3
  "description": "Test setup utilities for React applications",
4
- "version": "1.3.6",
4
+ "version": "1.3.10",
5
5
  "repository": "https://github.com/Trackunit/manager",
6
6
  "license": "SEE LICENSE IN LICENSE.txt",
7
7
  "engines": {