Skip to content

Commit d705e07

Browse files
committed
WIP: Code clean-up
1 parent ef05370 commit d705e07

19 files changed

+173
-160
lines changed

__tests__/api/bodyAttributes.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('body attributes', () => {
3131

3232
Object.keys(attributeList).forEach((attribute) => {
3333
it(`${attribute}`, () => {
34-
const attrValue = attributeList[attribute];
34+
const attrValue = attributeList[`${attribute}` as keyof BodyProps] as string;
3535

3636
const attr = {
3737
[attribute]: attrValue,

__tests__/api/client.test.tsx

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @jest-environment jsdom */
22

3-
import type { OnChangeClientState } from '../../src/Helmet';
3+
import type { OnChangeClientState } from '../../src';
44

55
import { Helmet } from '../../src';
66
import { renderClient } from '../../jest/browser-utils';
@@ -63,20 +63,20 @@ describe('onChangeClientState', () => {
6363
);
6464

6565
expect(addedTags?.baseTag).toBeDefined();
66-
expect(addedTags?.baseTag[0]).toBeDefined();
67-
expect(addedTags?.baseTag[0]?.outerHTML).toMatchSnapshot();
66+
expect(addedTags?.baseTag?.[0]).toBeDefined();
67+
expect(addedTags?.baseTag?.[0]?.outerHTML).toMatchSnapshot();
6868

6969
expect(addedTags?.metaTags).toBeDefined();
70-
expect(addedTags?.metaTags[0]).toBeDefined();
71-
expect(addedTags?.metaTags[0]?.outerHTML).toMatchSnapshot();
70+
expect(addedTags?.metaTags?.[0]).toBeDefined();
71+
expect(addedTags?.metaTags?.[0]?.outerHTML).toMatchSnapshot();
7272

7373
expect(addedTags?.linkTags).toBeDefined();
74-
expect(addedTags?.linkTags[0]).toBeDefined();
75-
expect(addedTags?.linkTags[0]?.outerHTML).toMatchSnapshot();
74+
expect(addedTags?.linkTags?.[0]).toBeDefined();
75+
expect(addedTags?.linkTags?.[0]?.outerHTML).toMatchSnapshot();
7676

7777
expect(addedTags?.scriptTags).toBeDefined();
78-
expect(addedTags?.scriptTags[0]).toBeDefined();
79-
expect(addedTags?.scriptTags[0]?.outerHTML).toMatchSnapshot();
78+
expect(addedTags?.scriptTags?.[0]).toBeDefined();
79+
expect(addedTags?.scriptTags?.[0]?.outerHTML).toMatchSnapshot();
8080

8181
expect(removedTags).toEqual({});
8282
});
@@ -142,20 +142,20 @@ describe('onChangeClientState', () => {
142142
);
143143

144144
expect(addedTags?.baseTag).toBeDefined();
145-
expect(addedTags?.baseTag[0]).toBeDefined();
146-
expect(addedTags?.baseTag[0]?.outerHTML).toMatchSnapshot();
145+
expect(addedTags?.baseTag?.[0]).toBeDefined();
146+
expect(addedTags?.baseTag?.[0]?.outerHTML).toMatchSnapshot();
147147

148148
expect(addedTags?.metaTags).toBeDefined();
149-
expect(addedTags?.metaTags[0]).toBeDefined();
150-
expect(addedTags?.metaTags[0]?.outerHTML).toMatchSnapshot();
149+
expect(addedTags?.metaTags?.[0]).toBeDefined();
150+
expect(addedTags?.metaTags?.[0]?.outerHTML).toMatchSnapshot();
151151

152152
expect(addedTags?.linkTags).toBeDefined();
153-
expect(addedTags?.linkTags[0]).toBeDefined();
154-
expect(addedTags?.linkTags[0]?.outerHTML).toMatchSnapshot();
153+
expect(addedTags?.linkTags?.[0]).toBeDefined();
154+
expect(addedTags?.linkTags?.[0]?.outerHTML).toMatchSnapshot();
155155

156156
expect(addedTags?.scriptTags).toBeDefined();
157-
expect(addedTags?.scriptTags[0]).toBeDefined();
158-
expect(addedTags?.scriptTags[0]?.outerHTML).toMatchSnapshot();
157+
expect(addedTags?.scriptTags?.[0]).toBeDefined();
158+
expect(addedTags?.scriptTags?.[0]?.outerHTML).toMatchSnapshot();
159159

160160
expect(removedTags).toEqual({});
161161
});

__tests__/api/htmlAttributes.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ describe('html attributes', () => {
4949
renderClient(
5050
<Helmet
5151
htmlAttributes={{
52+
// @ts-expect-error "pre-existing"
5253
amp: undefined,
5354
}}
5455
/>,
@@ -65,6 +66,7 @@ describe('html attributes', () => {
6566
<Helmet
6667
htmlAttributes={{
6768
lang: 'en',
69+
// @ts-expect-error "pre-existing"
6870
amp: undefined,
6971
}}
7072
/>,
@@ -84,6 +86,7 @@ describe('html attributes', () => {
8486
<Helmet
8587
htmlAttributes={{
8688
lang: 'en',
89+
// @ts-expect-error "pre-existing"
8790
amp: undefined,
8891
}}
8992
/>,
@@ -113,6 +116,7 @@ describe('html attributes', () => {
113116
<Helmet
114117
htmlAttributes={{
115118
lang: 'en',
119+
// @ts-expect-error "pre-existing"
116120
amp: undefined,
117121
}}
118122
/>,
@@ -155,6 +159,7 @@ describe('html attributes', () => {
155159
renderClient(
156160
<Helmet
157161
htmlAttributes={{
162+
// @ts-expect-error "pre-existing"
158163
test: 'helmet-attr',
159164
}}
160165
/>,
@@ -170,6 +175,7 @@ describe('html attributes', () => {
170175
renderClient(
171176
<Helmet
172177
htmlAttributes={{
178+
// @ts-expect-error "pre-existing"
173179
test: 'helmet-attr',
174180
}}
175181
/>,

__tests__/api/script.test.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ describe('script tags', () => {
126126
script={[
127127
{
128128
src: 'foo.js',
129-
// @ts-expect-error "pre-existing"
130129
async: undefined,
131130
},
132131
]}
@@ -144,7 +143,6 @@ describe('script tags', () => {
144143
<Helmet
145144
script={[
146145
{
147-
// @ts-expect-error "pre-existing"
148146
src: undefined,
149147
type: 'text/javascript',
150148
},
@@ -163,7 +161,6 @@ describe('script tags', () => {
163161
<Helmet
164162
script={[
165163
{
166-
// @ts-expect-error "pre-existing"
167164
innerHTML: undefined,
168165
},
169166
]}

__tests__/api/style.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ describe('style tags', () => {
8686
<Helmet
8787
style={[
8888
{
89-
// @ts-expect-error "pre-existing"
9089
cssText: undefined,
9190
},
9291
]}

__tests__/deferred.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Helmet } from '../src';
22

3-
import { renderClient } from '../jest/server-utils';
3+
import { renderClient } from '../jest/browser-utils';
44

55
declare global {
66
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions

__tests__/misc.test.tsx

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { Helmet } from '../src';
44
import { HELMET_ATTRIBUTE } from '../src/constants';
5-
import type { OnChangeClientState } from '../src/Helmet';
5+
import type { OnChangeClientState } from '../src';
66

77
import { renderClient } from '../jest/browser-utils';
88

@@ -104,11 +104,11 @@ describe('misc', () => {
104104
removedTags = onChange.mock.calls[0]![2];
105105

106106
expect(addedTags).toHaveProperty('metaTags');
107-
expect(addedTags.metaTags[0]).toBeDefined();
108-
expect(addedTags.metaTags[0]?.outerHTML).toMatchSnapshot();
107+
expect(addedTags.metaTags?.[0]).toBeDefined();
108+
expect(addedTags.metaTags?.[0]?.outerHTML).toMatchSnapshot();
109109
expect(addedTags).toHaveProperty('linkTags');
110-
expect(addedTags.linkTags[0]).toBeDefined();
111-
expect(addedTags.linkTags[0]?.outerHTML).toMatchSnapshot();
110+
expect(addedTags.linkTags?.[0]).toBeDefined();
111+
expect(addedTags.linkTags?.[0]?.outerHTML).toMatchSnapshot();
112112
expect(removedTags).toEqual({});
113113

114114
// Re-rendering will pass new props to an already mounted Helmet
@@ -137,14 +137,14 @@ describe('misc', () => {
137137
removedTags = onChange.mock.calls[1]?.[2];
138138

139139
expect(addedTags).toHaveProperty('metaTags');
140-
expect(addedTags?.metaTags[0]).toBeDefined();
141-
expect(addedTags?.metaTags[0]?.outerHTML).toMatchSnapshot();
140+
expect(addedTags?.metaTags?.[0]).toBeDefined();
141+
expect(addedTags?.metaTags?.[0]?.outerHTML).toMatchSnapshot();
142142
expect(addedTags).toHaveProperty('linkTags');
143-
expect(addedTags?.linkTags[0]).toBeDefined();
144-
expect(addedTags?.linkTags[0]?.outerHTML).toMatchSnapshot();
143+
expect(addedTags?.linkTags?.[0]).toBeDefined();
144+
expect(addedTags?.linkTags?.[0]?.outerHTML).toMatchSnapshot();
145145
expect(removedTags).toHaveProperty('metaTags');
146-
expect(removedTags?.metaTags[0]).toBeDefined();
147-
expect(removedTags?.metaTags[0]?.outerHTML).toMatchSnapshot();
146+
expect(removedTags?.metaTags?.[0]).toBeDefined();
147+
expect(removedTags?.metaTags?.[0]?.outerHTML).toMatchSnapshot();
148148
expect(removedTags).not.toHaveProperty('linkTags');
149149
});
150150

@@ -271,11 +271,11 @@ describe('misc', () => {
271271
removedTags = onChange.mock.calls[0]![2];
272272

273273
expect(addedTags).toHaveProperty('metaTags');
274-
expect(addedTags.metaTags[0]).toBeDefined();
275-
expect(addedTags.metaTags[0]?.outerHTML).toMatchSnapshot();
274+
expect(addedTags.metaTags?.[0]).toBeDefined();
275+
expect(addedTags.metaTags?.[0]?.outerHTML).toMatchSnapshot();
276276
expect(addedTags).toHaveProperty('linkTags');
277-
expect(addedTags.linkTags[0]).toBeDefined();
278-
expect(addedTags.linkTags[0]?.outerHTML).toMatchSnapshot();
277+
expect(addedTags.linkTags?.[0]).toBeDefined();
278+
expect(addedTags.linkTags?.[0]?.outerHTML).toMatchSnapshot();
279279
expect(removedTags).toEqual({});
280280

281281
// Re-rendering will pass new props to an already mounted Helmet
@@ -293,14 +293,14 @@ describe('misc', () => {
293293
removedTags = onChange.mock.calls[1]![2];
294294

295295
expect(addedTags).toHaveProperty('metaTags');
296-
expect(addedTags.metaTags[0]).toBeDefined();
297-
expect(addedTags.metaTags[0]?.outerHTML).toMatchSnapshot();
296+
expect(addedTags.metaTags?.[0]).toBeDefined();
297+
expect(addedTags.metaTags?.[0]?.outerHTML).toMatchSnapshot();
298298
expect(addedTags).toHaveProperty('linkTags');
299-
expect(addedTags.linkTags[0]).toBeDefined();
300-
expect(addedTags.linkTags[0]?.outerHTML).toMatchSnapshot();
299+
expect(addedTags.linkTags?.[0]).toBeDefined();
300+
expect(addedTags.linkTags?.[0]?.outerHTML).toMatchSnapshot();
301301
expect(removedTags).toHaveProperty('metaTags');
302-
expect(removedTags.metaTags[0]).toBeDefined();
303-
expect(removedTags.metaTags[0]?.outerHTML).toMatchSnapshot();
302+
expect(removedTags.metaTags?.[0]).toBeDefined();
303+
expect(removedTags.metaTags?.[0]?.outerHTML).toMatchSnapshot();
304304
expect(removedTags).not.toHaveProperty('linkTags');
305305
});
306306

__tests__/server/link.test.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ describe('server', () => {
3232
expect(link).toEqual(expect.objectContaining({ type: 'link' }));
3333
});
3434

35-
const markup = ReactServer.renderToStaticMarkup(linkComponent as ReactNode);
35+
const markup = ReactServer.renderToStaticMarkup(
36+
linkComponent as ReactNode,
37+
);
3638

3739
expect(markup).toMatchSnapshot();
3840
});
@@ -78,7 +80,9 @@ describe('server', () => {
7880
expect(link).toEqual(expect.objectContaining({ type: 'link' }));
7981
});
8082

81-
const markup = ReactServer.renderToStaticMarkup(linkComponent as ReactNode);
83+
const markup = ReactServer.renderToStaticMarkup(
84+
linkComponent as ReactNode,
85+
);
8286

8387
expect(markup).toMatchSnapshot();
8488
});

__tests__/server/noscript.test.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ describe('server', () => {
2525
expect(head?.noscript).toBeDefined();
2626
expect(head!.noscript.toComponent).toBeDefined();
2727

28-
const noscriptComponent = head?.noscript.toComponent() as unknown as Element[];
28+
const noscriptComponent
29+
= head?.noscript.toComponent() as unknown as Element[];
2930

3031
expect(noscriptComponent).toEqual(isArray);
3132
expect(noscriptComponent).toHaveLength(2);
@@ -34,7 +35,9 @@ describe('server', () => {
3435
expect(noscript).toEqual(expect.objectContaining({ type: 'noscript' }));
3536
});
3637

37-
const markup = ReactServer.renderToStaticMarkup(noscriptComponent as ReactNode);
38+
const markup = ReactServer.renderToStaticMarkup(
39+
noscriptComponent as ReactNode,
40+
);
3841

3942
expect(markup).toMatchSnapshot();
4043
});
@@ -52,7 +55,8 @@ describe('server', () => {
5255
expect(head?.noscript).toBeDefined();
5356
expect(head!.noscript.toComponent).toBeDefined();
5457

55-
const noscriptComponent = head?.noscript.toComponent() as unknown as Element[];
58+
const noscriptComponent
59+
= head?.noscript.toComponent() as unknown as Element[];
5660

5761
expect(noscriptComponent).toEqual(isArray);
5862
expect(noscriptComponent).toHaveLength(2);
@@ -61,7 +65,9 @@ describe('server', () => {
6165
expect(noscript).toEqual(expect.objectContaining({ type: 'noscript' }));
6266
});
6367

64-
const markup = ReactServer.renderToStaticMarkup(noscriptComponent as ReactNode);
68+
const markup = ReactServer.renderToStaticMarkup(
69+
noscriptComponent as ReactNode,
70+
);
6571

6672
expect(markup).toMatchSnapshot();
6773
});

__tests__/server/script.test.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ describe('server', () => {
2525
expect(head?.script).toBeDefined();
2626
expect(head!.script.toComponent).toBeDefined();
2727

28-
const scriptComponent = head?.script.toComponent() as unknown as Element[];
28+
const scriptComponent
29+
= head?.script.toComponent() as unknown as Element[];
2930

3031
expect(scriptComponent).toEqual(isArray);
3132
expect(scriptComponent).toHaveLength(2);
@@ -73,7 +74,8 @@ describe('server', () => {
7374
expect(head?.script).toBeDefined();
7475
expect(head!.script.toComponent).toBeDefined();
7576

76-
const scriptComponent = head?.script.toComponent() as unknown as Element[];
77+
const scriptComponent
78+
= head?.script.toComponent() as unknown as Element[];
7779

7880
expect(scriptComponent).toEqual(isArray);
7981
expect(scriptComponent).toHaveLength(2);

0 commit comments

Comments
 (0)