Skip to content

Commit 6fdc0d3

Browse files
committed
fix: tests to support --default-client-callbacks option for the createAPIClient()
1 parent 6154234 commit 6fdc0d3

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

packages/react-client/src/tests/qraftAPIClient.test.tsx

+22-14
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
} from '@tanstack/react-query';
2121
import { act, renderHook, waitFor } from '@testing-library/react';
2222
import React from 'react';
23-
import { beforeEach, describe, expect, it, vi } from 'vitest';
23+
import { describe, expect, it, vi } from 'vitest';
2424
import { qraftAPIClient, requestFn } from '../index.js';
2525
import { createPredefinedParametersRequestFn } from './fixtures/api/create-predefined-parameters-request-fn.js';
2626
import {
@@ -1880,8 +1880,8 @@ describe('Qraft uses "fetchQuery(...) & "prefetchQuery(...)" & "ensureQueryData(
18801880

18811881
it('throws an error if requestFn is not provided', async () => {
18821882
const qraft = createAPIClient({
1883+
// @ts-expect-error - incorrect usage case, `requestFn` is not defined
18831884
queryClient: new QueryClient(),
1884-
// @ts-expect-error - incorrect usage case
18851885
requestFn: undefined,
18861886
baseUrl: 'http://any',
18871887
});
@@ -4533,43 +4533,43 @@ describe('Qraft is type-safe if client created with "QueryClient" only', () => {
45334533
});
45344534

45354535
describe('Qraft API Client primitive conversions', () => {
4536-
let qraft: ReturnType<typeof createAPIClient>;
4537-
4538-
beforeEach(() => {
4539-
qraft = createAPIClient({ queryClient: new QueryClient() });
4540-
});
4541-
45424536
describe('Root level conversions', () => {
45434537
it('should handle string conversion', () => {
4538+
const qraft = createAPIClient({ queryClient: new QueryClient() });
45444539
expect(String(qraft)).toBe(qraft.toString());
45454540
expect(`${qraft}`).toBe(qraft.toString());
45464541
});
45474542

45484543
it('should handle number conversion', () => {
4544+
const qraft = createAPIClient({ queryClient: new QueryClient() });
45494545
expect(Number(qraft)).toBeNaN();
45504546
expect(+qraft).toBeNaN();
45514547
});
45524548

45534549
it('should handle JSON serialization', () => {
4550+
const qraft = createAPIClient({ queryClient: new QueryClient() });
45544551
expect(JSON.stringify(qraft)).toBe(
45554552
JSON.stringify(JSON.stringify(services))
45564553
);
45574554
});
45584555

45594556
it('toJSON() returns JSON string', () => {
4557+
const qraft = createAPIClient({ queryClient: new QueryClient() });
45604558
expect(
45614559
// @ts-expect-error - toJSON() is not a standard method for Qraft API Client
45624560
qraft.toJSON()
45634561
).toBe(JSON.stringify(services));
45644562
});
45654563

45664564
it('should handle valueOf()', () => {
4565+
const qraft = createAPIClient({ queryClient: new QueryClient() });
45674566
const value = qraft.valueOf();
45684567
expect(typeof value).toBe('object');
45694568
expect(value).toBe(services);
45704569
});
45714570

45724571
it('should handle Symbol.toStringTag', () => {
4572+
const qraft = createAPIClient({ queryClient: new QueryClient() });
45734573
expect(Object.prototype.toString.call(qraft)).toBe(
45744574
'[object QraftAPIClient]'
45754575
);
@@ -4578,6 +4578,7 @@ describe('Qraft API Client primitive conversions', () => {
45784578

45794579
describe('Service level conversions', () => {
45804580
it('should handle string conversion', () => {
4581+
const qraft = createAPIClient({ queryClient: new QueryClient() });
45814582
expect(String(qraft.approvalPolicies)).toBe(
45824583
qraft.approvalPolicies.toString()
45834584
);
@@ -4587,23 +4588,27 @@ describe('Qraft API Client primitive conversions', () => {
45874588
});
45884589

45894590
it('should handle number conversion', () => {
4591+
const qraft = createAPIClient({ queryClient: new QueryClient() });
45904592
expect(Number(qraft.approvalPolicies)).toBeNaN();
45914593
expect(+qraft.approvalPolicies).toBeNaN();
45924594
});
45934595

45944596
it('should handle JSON serialization', () => {
4597+
const qraft = createAPIClient({ queryClient: new QueryClient() });
45954598
expect(JSON.stringify(qraft.approvalPolicies)).toBe(
45964599
JSON.stringify(JSON.stringify(services.approvalPolicies))
45974600
);
45984601
});
45994602

46004603
it('should handle valueOf()', () => {
4604+
const qraft = createAPIClient({ queryClient: new QueryClient() });
46014605
const value = qraft.approvalPolicies.valueOf();
46024606
expect(typeof value).toBe('object');
46034607
expect(value).toBe(qraft.approvalPolicies.valueOf());
46044608
});
46054609

46064610
it('should handle Symbol.toStringTag', () => {
4611+
const qraft = createAPIClient({ queryClient: new QueryClient() });
46074612
expect(Object.prototype.toString.call(qraft.approvalPolicies)).toBe(
46084613
'[object QraftAPIClient]'
46094614
);
@@ -4612,16 +4617,19 @@ describe('Qraft API Client primitive conversions', () => {
46124617

46134618
describe('Operation level conversions', () => {
46144619
it('should handle string conversion', () => {
4620+
const qraft = createAPIClient({ queryClient: new QueryClient() });
46154621
expect(String(qraft.approvalPolicies.getApprovalPoliciesId)).toBe(
46164622
qraft.approvalPolicies.getApprovalPoliciesId.toString()
46174623
);
46184624
});
46194625

46204626
it('should handle number conversion', () => {
4627+
const qraft = createAPIClient({ queryClient: new QueryClient() });
46214628
expect(Number(qraft.approvalPolicies.getApprovalPoliciesId)).toBeNaN();
46224629
});
46234630

46244631
it('should handle JSON serialization', () => {
4632+
const qraft = createAPIClient({ queryClient: new QueryClient() });
46254633
expect(JSON.stringify(qraft.approvalPolicies.getApprovalPoliciesId)).toBe(
46264634
JSON.stringify(
46274635
JSON.stringify(services.approvalPolicies.getApprovalPoliciesId)
@@ -4630,11 +4638,13 @@ describe('Qraft API Client primitive conversions', () => {
46304638
});
46314639

46324640
it('should handle valueOf()', () => {
4641+
const qraft = createAPIClient({ queryClient: new QueryClient() });
46334642
const value = qraft.approvalPolicies.getApprovalPoliciesId.valueOf();
46344643
expect(typeof value).toBe('object');
46354644
});
46364645

46374646
it('should handle Symbol.toStringTag', () => {
4647+
const qraft = createAPIClient({ queryClient: new QueryClient() });
46384648
expect(
46394649
Object.prototype.toString.call(
46404650
qraft.approvalPolicies.getApprovalPoliciesId
@@ -4645,22 +4655,19 @@ describe('Qraft API Client primitive conversions', () => {
46454655
});
46464656

46474657
describe('Qraft API Client console logging', () => {
4648-
let qraft: ReturnType<typeof createAPIClient>;
4649-
4650-
beforeEach(() => {
4651-
qraft = createAPIClient({ queryClient: new QueryClient() });
4652-
});
4653-
46544658
describe('Individual elements logging', () => {
46554659
it('should log root client without errors', () => {
4660+
const qraft = createAPIClient({ queryClient: new QueryClient() });
46564661
expect(() => console.log(qraft)).not.toThrow();
46574662
});
46584663

46594664
it('should log service without errors', () => {
4665+
const qraft = createAPIClient({ queryClient: new QueryClient() });
46604666
expect(() => console.log(qraft.approvalPolicies)).not.toThrow();
46614667
});
46624668

46634669
it('should log operation without errors', () => {
4670+
const qraft = createAPIClient({ queryClient: new QueryClient() });
46644671
expect(() =>
46654672
console.log(qraft.approvalPolicies.getApprovalPoliciesId)
46664673
).not.toThrow();
@@ -4669,6 +4676,7 @@ describe('Qraft API Client console logging', () => {
46694676

46704677
describe('Multiple levels mixed logging', () => {
46714678
it('should log multiple client elements without errors', () => {
4679+
const qraft = createAPIClient({ queryClient: new QueryClient() });
46724680
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
46734681

46744682
try {

0 commit comments

Comments
 (0)