Skip to content

Commit 704cd45

Browse files
committed
fix: resolve ESLint errors and deprecation warnings
1 parent 84e51ad commit 704cd45

5 files changed

Lines changed: 70 additions & 61 deletions

File tree

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import type { JSX } from 'solid-js';
2+
3+
import { MetaProvider } from '@solidjs/meta';
14
import { render } from '@solidjs/testing-library';
25
import { expect, describe, test, vi } from 'vitest';
3-
import { MetaProvider } from '@solidjs/meta';
4-
import type { JSX } from 'solid-js';
6+
57
import Head from './Head';
68

79
// Mock the AppConfig to avoid import issues
@@ -11,91 +13,99 @@ vi.mock('@/constants/AppConfig', () => ({
1113
description: 'Test description',
1214
og: {
1315
image: {
14-
url: 'https://example.com/default-og-image.jpg'
15-
}
16-
}
17-
}
16+
url: 'https://example.com/default-og-image.jpg',
17+
},
18+
},
19+
},
1820
}));
1921

2022
describe('Head component', () => {
2123
const renderWithMeta = (component: () => JSX.Element) => {
22-
return render(() => (
23-
<MetaProvider>
24-
{component()}
25-
</MetaProvider>
26-
));
24+
return render(() => <MetaProvider>{component()}</MetaProvider>);
2725
};
2826

2927
test('should render with default title and description', () => {
3028
const { unmount } = renderWithMeta(() => <Head />);
31-
29+
3230
// Check if document head contains the expected meta tags
3331
expect(document.title).toBe('Test Site');
34-
35-
const metaDescription = document.querySelector('meta[name="description"]');
32+
33+
// eslint-disable-next-line testing-library/no-node-access
34+
const metaDescription = document.head.querySelector(
35+
'meta[name="description"]',
36+
);
3637
expect(metaDescription?.getAttribute('content')).toBe('Test description');
37-
38+
3839
unmount();
3940
});
4041

4142
test('should render with custom title and description', () => {
4243
const customTitle = 'Custom Page';
4344
const customDescription = 'Custom page description';
44-
45+
4546
const { unmount } = renderWithMeta(() => (
4647
<Head title={customTitle} description={customDescription} />
4748
));
48-
49+
4950
expect(document.title).toBe('Custom Page | Test Site');
50-
51-
const metaDescription = document.querySelector('meta[name="description"]');
51+
52+
// eslint-disable-next-line testing-library/no-node-access
53+
const metaDescription = document.head.querySelector(
54+
'meta[name="description"]',
55+
);
5256
expect(metaDescription?.getAttribute('content')).toBe(customDescription);
53-
57+
5458
unmount();
5559
});
5660

5761
test('should use website type when canonical is undefined', () => {
5862
const { unmount } = renderWithMeta(() => <Head />);
59-
60-
const ogType = document.querySelector('meta[property="og:type"]');
63+
64+
// eslint-disable-next-line testing-library/no-node-access
65+
const ogType = document.head.querySelector('meta[property="og:type"]');
6166
expect(ogType?.getAttribute('content')).toBe('website');
62-
67+
6368
unmount();
6469
});
6570

6671
test('should use article type when canonical is provided', () => {
6772
const { unmount } = renderWithMeta(() => <Head canonical="/test" />);
68-
69-
const ogType = document.querySelector('meta[property="og:type"]');
73+
74+
// eslint-disable-next-line testing-library/no-node-access
75+
const ogType = document.head.querySelector('meta[property="og:type"]');
7076
expect(ogType?.getAttribute('content')).toBe('article');
71-
77+
7278
unmount();
7379
});
7480

7581
test('should use custom OG image when provided', () => {
7682
const customOgImage = {
7783
og: {
7884
image: {
79-
url: '/custom-image.jpg'
80-
}
81-
}
85+
url: '/custom-image.jpg',
86+
},
87+
},
8288
};
83-
89+
8490
const { unmount } = renderWithMeta(() => <Head {...customOgImage} />);
85-
86-
const ogImage = document.querySelector('meta[property="og:image"]');
91+
92+
// eslint-disable-next-line testing-library/no-node-access
93+
const ogImage = document.head.querySelector('meta[property="og:image"]');
8794
// The actual implementation prepends siteUrl, but since siteUrl is empty in test, it just returns the path
8895
expect(ogImage?.getAttribute('content')).toContain('custom-image.jpg');
89-
96+
9097
unmount();
9198
});
9299

93100
test('should use default OG image when custom image is not provided', () => {
94101
const { unmount } = renderWithMeta(() => <Head />);
95-
96-
const ogImage = document.querySelector('meta[property="og:image"]');
97-
expect(ogImage?.getAttribute('content')).toBe('https://example.com/default-og-image.jpg');
98-
102+
103+
// eslint-disable-next-line testing-library/no-node-access
104+
const ogImage = document.head.querySelector('meta[property="og:image"]');
105+
expect(ogImage?.getAttribute('content')).toBe(
106+
'https://example.com/default-og-image.jpg',
107+
);
108+
99109
unmount();
100110
});
101-
});
111+
});

apps/solidjs-boilerplate/src/hooks/useFetchPost.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { createQuery } from '@tanstack/solid-query';
2-
3-
import type { Post } from '@/types/api/post.interface';
1+
import { useQuery } from '@tanstack/solid-query';
42

53
// import type { Post } from '@/types/api/post.interface';
64

@@ -15,7 +13,7 @@ const useFetchPost = (id: string) => {
1513
// queryFn: fetchData,
1614
// }));
1715

18-
const query = createQuery(() => ({
16+
const query = useQuery(() => ({
1917
// Array Keys with variables
2018
// @ https://tanstack.com/query/v4/docs/react/guides/query-keys?from=reactQueryV3&original=https%3A%2F%2Freact-query-v3.tanstack.com%2Fguides%2Fquery-keys#array-keys-with-variables
2119
queryKey: [`/posts/`, id],

apps/solidjs-boilerplate/src/hooks/useFetchPostList.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { createQuery } from '@tanstack/solid-query';
2-
3-
import type { Post } from '@/types/api/post.interface';
1+
import { useQuery } from '@tanstack/solid-query';
42

53
// import type { Post } from '@/types/api/post.interface';
64

@@ -15,7 +13,7 @@ const useFetchPostList = () => {
1513
// queryFn: fetchData,
1614
// }));
1715

18-
const query = createQuery(() => ({
16+
const query = useQuery(() => ({
1917
queryKey: ['/posts'],
2018
queryFn: async () => {
2119
const result = await fetch(`${apiEndpointUrl}/posts`);
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
import { expect, describe, test } from 'vitest';
2+
23
import { formatDescription, buildCanonicalUrl } from './format';
34

45
describe('format utilities', () => {
56
describe('formatDescription', () => {
67
test('should remove HTML tags and truncate string', () => {
7-
const input = '<p>This is a <strong>test</strong> description with some HTML tags</p>';
8+
const input =
9+
'<p>This is a <strong>test</strong> description with some HTML tags</p>';
810
const result = formatDescription(input);
9-
11+
1012
expect(result).toBe('This is a test description with some HTML tags');
1113
expect(result.length).toBeLessThanOrEqual(120);
1214
});
1315

1416
test('should remove newlines', () => {
1517
const input = 'Line 1\nLine 2\nLine 3';
1618
const result = formatDescription(input);
17-
19+
1820
expect(result).toBe('Line 1Line 2Line 3');
1921
});
2022

2123
test('should truncate long descriptions to 120 characters or less', () => {
2224
const longText = 'a'.repeat(200);
2325
const result = formatDescription(longText);
24-
26+
2527
// The actual implementation uses truncate package, which may add ellipsis
2628
expect(result.length).toBeLessThanOrEqual(123); // Account for possible ellipsis
2729
});
@@ -31,23 +33,23 @@ describe('format utilities', () => {
3133
test('should build canonical URL with site URL', () => {
3234
const path = '/test-page';
3335
const result = buildCanonicalUrl(path);
34-
36+
3537
// In test environment, siteUrl is empty, so result should just be the path
3638
expect(result).toBe('/test-page');
3739
});
3840

3941
test('should handle empty path', () => {
4042
const path = '';
4143
const result = buildCanonicalUrl(path);
42-
44+
4345
expect(result).toBe('');
4446
});
4547

4648
test('should handle path with query parameters', () => {
4749
const path = '/page?param=value';
4850
const result = buildCanonicalUrl(path);
49-
51+
5052
expect(result).toBe('/page?param=value');
5153
});
5254
});
53-
});
55+
});

apps/solidjs-boilerplate/src/utils/sanitize.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import { expect, describe, test } from 'vitest';
2+
23
import { sanitize, nl2br, sanitizeTextarea, escAttr } from './sanitize';
34

45
describe('sanitize utilities', () => {
56
describe('sanitize', () => {
67
test('should sanitize HTML while preserving safe tags', () => {
78
const input = '<p>Safe content</p><script>alert("unsafe")</script>';
89
const result = sanitize(input);
9-
10+
1011
expect(result).toContain('<p>Safe content</p>');
1112
expect(result).not.toContain('<script>');
1213
});
1314

1415
test('should preserve target attribute', () => {
1516
const input = '<a href="#" target="_blank">Link</a>';
1617
const result = sanitize(input);
17-
18+
1819
expect(result).toContain('target="_blank"');
1920
});
2021
});
@@ -23,7 +24,7 @@ describe('sanitize utilities', () => {
2324
test('should convert newlines to <br> tags', () => {
2425
const input = 'Line 1\nLine 2\r\nLine 3\rLine 4';
2526
const result = nl2br(input);
26-
27+
2728
expect(result).toBe('Line 1<br>Line 2<br>Line 3<br>Line 4');
2829
});
2930

@@ -37,7 +38,7 @@ describe('sanitize utilities', () => {
3738
test('should sanitize and convert newlines', () => {
3839
const input = '<script>alert("test")</script>\nLine 2';
3940
const result = sanitizeTextarea(input);
40-
41+
4142
expect(result).not.toContain('<script>');
4243
expect(result).toContain('<br>');
4344
});
@@ -47,7 +48,7 @@ describe('sanitize utilities', () => {
4748
test('should escape HTML entities and remove tags', () => {
4849
const input = '<script>alert("test")</script>&lt;test&gt;';
4950
const result = escAttr(input);
50-
51+
5152
expect(result).not.toContain('<script>');
5253
expect(result).not.toContain('<');
5354
expect(result).not.toContain('>');
@@ -56,7 +57,7 @@ describe('sanitize utilities', () => {
5657
test('should handle special characters', () => {
5758
const input = 'Test & "quotes" and \'apostrophes\'';
5859
const result = escAttr(input);
59-
60+
6061
expect(result).toContain('&amp;');
6162
expect(result).toContain('&quot;');
6263
});
@@ -66,4 +67,4 @@ describe('sanitize utilities', () => {
6667
expect(result).toBe('');
6768
});
6869
});
69-
});
70+
});

0 commit comments

Comments
 (0)