Skip to content

Commit 9556704

Browse files
committed
test(next-drupal): replace @ts-ignore with @ts-expect-error
1 parent c9ae778 commit 9556704

File tree

8 files changed

+74
-25
lines changed

8 files changed

+74
-25
lines changed

packages/next-drupal/tests/.eslintrc.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
{
55
"files": ["*.test.ts"],
66
"rules": {
7-
"@typescript-eslint/ban-ts-comment": "off"
7+
"@typescript-eslint/ban-ts-comment": [
8+
"error",
9+
{
10+
"ts-expect-error": false,
11+
"ts-ignore": true,
12+
"ts-nocheck": true,
13+
"ts-check": false
14+
}
15+
]
816
}
917
}
1018
]

packages/next-drupal/tests/NextDrupal/basic-methods.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ describe("deserialize()", () => {
5252
test("allows for custom data serializer", async () => {
5353
const deserializer: JsonDeserializer = (
5454
body: { data: { id: string; attributes: { title: string } } },
55-
options: { pathPrefix: string }
55+
options: { titlePrefix: string }
5656
) => {
5757
return {
5858
id: body.data.id,
59-
title: `${options.pathPrefix}: ${body.data.attributes.title}`,
59+
title:
60+
(options.titlePrefix ? `${options.titlePrefix}: ` : "") +
61+
body.data.attributes.title,
6062
}
6163
}
6264
const drupal = new NextDrupal(BASE_URL, {
@@ -71,7 +73,7 @@ describe("deserialize()", () => {
7173
expect(response.status).toBe(200)
7274
const json = await response.json()
7375
const article = drupal.deserialize(json, {
74-
pathPrefix: "TITLE",
76+
titlePrefix: "TITLE",
7577
}) as DrupalNode
7678

7779
expect(article).toMatchSnapshot()

packages/next-drupal/tests/NextDrupal/constructor.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jest.mock("jsona", () => {
2727
})
2828

2929
beforeEach(() => {
30+
// @ts-expect-error
3031
Jsona.mockClear()
3132
})
3233

@@ -108,6 +109,7 @@ describe("options parameter", () => {
108109
expect(Jsona).toBeCalledTimes(1)
109110

110111
const deserializeMock = new Jsona().deserialize
112+
// @ts-expect-error
111113
deserializeMock.mockClear()
112114
const args: Parameters<JsonDeserializer> = [{}, { options: true }]
113115
drupal.deserialize(...args)

packages/next-drupal/tests/NextDrupalBase/constructor.test.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@ describe("baseUrl parameter", () => {
2121
})
2222

2323
test("throws error given an invalid baseUrl", () => {
24-
// @ts-ignore
25-
expect(() => new NextDrupalBase()).toThrow(
26-
"The 'baseUrl' param is required."
27-
)
28-
29-
// @ts-ignore
30-
expect(() => new NextDrupalBase({})).toThrow(
31-
"The 'baseUrl' param is required."
32-
)
24+
expect(
25+
() =>
26+
// @ts-expect-error
27+
new NextDrupalBase()
28+
).toThrow("The 'baseUrl' param is required.")
29+
30+
expect(
31+
() =>
32+
// @ts-expect-error
33+
new NextDrupalBase({})
34+
).toThrow("The 'baseUrl' param is required.")
3335
})
3436

3537
test("announces debug mode when turned on", () => {

packages/next-drupal/tests/NextDrupalBase/fetch-methods.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ describe("getAccessToken()", () => {
233233

234234
await expect(
235235
drupal.getAccessToken(
236-
// @ts-ignore
236+
// @ts-expect-error
237237
{ clientId: clientIdSecret.clientId }
238238
)
239239
).rejects.toThrow(errorMessage)
@@ -563,7 +563,7 @@ describe("getAuthorizationHeader()", () => {
563563

564564
await expect(
565565
drupal.getAuthorizationHeader(
566-
// @ts-ignore
566+
// @ts-expect-error
567567
auth
568568
)
569569
).rejects.toThrow(

packages/next-drupal/tests/NextDrupalBase/getters-setters.test.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe("auth", () => {
3434
test("missing username", () => {
3535
expect(() => {
3636
const drupal = new NextDrupalBase(BASE_URL)
37-
// @ts-ignore
37+
// @ts-expect-error
3838
drupal.auth = {
3939
password: "password",
4040
}
@@ -46,7 +46,7 @@ describe("auth", () => {
4646
test("missing password", () => {
4747
expect(() => {
4848
const drupal = new NextDrupalBase(BASE_URL)
49-
// @ts-ignore
49+
// @ts-expect-error
5050
drupal.auth = {
5151
username: "admin",
5252
}
@@ -60,7 +60,7 @@ describe("auth", () => {
6060
test("missing access_token", () => {
6161
expect(() => {
6262
const drupal = new NextDrupalBase(BASE_URL)
63-
// @ts-ignore
63+
// @ts-expect-error
6464
drupal.auth = {
6565
token_type: mocks.auth.accessToken.token_type,
6666
}
@@ -72,7 +72,7 @@ describe("auth", () => {
7272
test("missing token_type", () => {
7373
expect(() => {
7474
const drupal = new NextDrupalBase(BASE_URL)
75-
// @ts-ignore
75+
// @ts-expect-error
7676
drupal.auth = {
7777
access_token: mocks.auth.accessToken.access_token,
7878
}
@@ -86,7 +86,7 @@ describe("auth", () => {
8686
test("missing clientId", () => {
8787
expect(() => {
8888
const drupal = new NextDrupalBase(BASE_URL)
89-
// @ts-ignore
89+
// @ts-expect-error
9090
drupal.auth = {
9191
clientSecret: mocks.auth.clientIdSecret.clientSecret,
9292
}
@@ -98,7 +98,7 @@ describe("auth", () => {
9898
test("missing clientSecret", () => {
9999
expect(() => {
100100
const drupal = new NextDrupalBase(BASE_URL)
101-
// @ts-ignore
101+
// @ts-expect-error
102102
drupal.auth = {
103103
clientId: mocks.auth.clientIdSecret.clientId,
104104
}
@@ -258,7 +258,13 @@ describe("token", () => {
258258
const after = getExpiresOn(accessToken)
259259

260260
expect(drupal.token).toBe(accessToken)
261-
expect(drupal._tokenExpiresOn).toBeGreaterThanOrEqual(before)
262-
expect(drupal._tokenExpiresOn).toBeLessThanOrEqual(after)
261+
expect(
262+
// @ts-expect-error
263+
drupal._tokenExpiresOn
264+
).toBeGreaterThanOrEqual(before)
265+
expect(
266+
// @ts-expect-error
267+
drupal._tokenExpiresOn
268+
).toBeLessThanOrEqual(after)
263269
})
264270
})

packages/next-drupal/tests/NextDrupalPages/constructor.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ describe("options parameter", () => {
1919
describe("serializer", () => {
2020
test("defaults to `new Jsona()`", () => {
2121
const drupal = new NextDrupalPages(BASE_URL)
22-
expect(drupal.serializer).toBeInstanceOf(Jsona)
22+
expect(
23+
// @ts-expect-error
24+
drupal.serializer
25+
).toBeInstanceOf(Jsona)
2326
})
2427

2528
test("sets up a custom serializer", () => {
@@ -37,7 +40,10 @@ describe("options parameter", () => {
3740
const drupal = new NextDrupalPages(BASE_URL, {
3841
serializer: customSerializer,
3942
})
40-
expect(drupal.serializer).toBe(customSerializer)
43+
expect(
44+
// @ts-expect-error
45+
drupal.serializer
46+
).toBe(customSerializer)
4147
})
4248
})
4349
})

packages/next-drupal/tests/NextDrupalPages/pages-router-methods.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,7 @@ describe("preview()", () => {
11201120
// Get values from our mocked request.
11211121
// eslint-disable-next-line @typescript-eslint/no-unused-vars
11221122
const { path, resourceVersion, plugin, secret, ...draftData } =
1123+
// @ts-expect-error
11231124
new NextApiRequest().query
11241125
const dataCookie = `${DRAFT_DATA_COOKIE_NAME}=${encodeURIComponent(
11251126
JSON.stringify({ path, resourceVersion, ...draftData })
@@ -1130,7 +1131,9 @@ describe("preview()", () => {
11301131
}
11311132

11321133
test("turns on preview mode and clears preview data", async () => {
1134+
// @ts-expect-error
11331135
const request = new NextApiRequest()
1136+
// @ts-expect-error
11341137
const response = new NextApiResponse()
11351138
const drupal = new NextDrupalPages(BASE_URL)
11361139
spyOnFetch({ responseBody: validationPayload })
@@ -1147,7 +1150,9 @@ describe("preview()", () => {
11471150

11481151
test("does not enable preview mode if validation fails", async () => {
11491152
const logger = mockLogger()
1153+
// @ts-expect-error
11501154
const request = new NextApiRequest()
1155+
// @ts-expect-error
11511156
const response = new NextApiResponse()
11521157
const drupal = new NextDrupalPages(BASE_URL, { debug: true, logger })
11531158
const status = 403
@@ -1171,7 +1176,9 @@ describe("preview()", () => {
11711176
})
11721177

11731178
test("does not turn on draft mode by default", async () => {
1179+
// @ts-expect-error
11741180
const request = new NextApiRequest()
1181+
// @ts-expect-error
11751182
const response = new NextApiResponse()
11761183
const drupal = new NextDrupalPages(BASE_URL)
11771184
spyOnFetch({ responseBody: validationPayload })
@@ -1186,7 +1193,9 @@ describe("preview()", () => {
11861193
})
11871194

11881195
test("optionally turns on draft mode", async () => {
1196+
// @ts-expect-error
11891197
const request = new NextApiRequest()
1198+
// @ts-expect-error
11901199
const response = new NextApiResponse()
11911200
const logger = mockLogger()
11921201
const drupal = new NextDrupalPages(BASE_URL, {
@@ -1208,7 +1217,9 @@ describe("preview()", () => {
12081217
})
12091218

12101219
test("updates preview mode cookie’s sameSite flag", async () => {
1220+
// @ts-expect-error
12111221
const request = new NextApiRequest()
1222+
// @ts-expect-error
12121223
const response = new NextApiResponse()
12131224
const drupal = new NextDrupalPages(BASE_URL)
12141225
spyOnFetch({ responseBody: validationPayload })
@@ -1232,7 +1243,9 @@ describe("preview()", () => {
12321243
})
12331244

12341245
test("redirects to the given path", async () => {
1246+
// @ts-expect-error
12351247
const request = new NextApiRequest()
1248+
// @ts-expect-error
12361249
const response = new NextApiResponse()
12371250
const logger = mockLogger()
12381251
const drupal = new NextDrupalPages(BASE_URL, { debug: true, logger })
@@ -1250,7 +1263,9 @@ describe("preview()", () => {
12501263
})
12511264

12521265
test("returns a 422 response on error", async () => {
1266+
// @ts-expect-error
12531267
const request = new NextApiRequest()
1268+
// @ts-expect-error
12541269
const response = new NextApiResponse()
12551270
const logger = mockLogger()
12561271
const drupal = new NextDrupalPages(BASE_URL, { debug: true, logger })
@@ -1269,7 +1284,9 @@ describe("preview()", () => {
12691284

12701285
describe("previewDisable()", () => {
12711286
test("clears preview data", async () => {
1287+
// @ts-expect-error
12721288
const request = new NextApiRequest()
1289+
// @ts-expect-error
12731290
const response = new NextApiResponse()
12741291
const drupal = new NextDrupalPages(BASE_URL)
12751292

@@ -1278,7 +1295,9 @@ describe("previewDisable()", () => {
12781295
})
12791296

12801297
test("disables draft mode", async () => {
1298+
// @ts-expect-error
12811299
const request = new NextApiRequest()
1300+
// @ts-expect-error
12821301
const response = new NextApiResponse()
12831302
const drupal = new NextDrupalPages(BASE_URL)
12841303

@@ -1287,7 +1306,9 @@ describe("previewDisable()", () => {
12871306
})
12881307

12891308
test("deletes the draft cookie", async () => {
1309+
// @ts-expect-error
12901310
const request = new NextApiRequest()
1311+
// @ts-expect-error
12911312
const response = new NextApiResponse()
12921313
const drupal = new NextDrupalPages(BASE_URL)
12931314

@@ -1299,7 +1320,9 @@ describe("previewDisable()", () => {
12991320
})
13001321

13011322
test('redirects to "/"', async () => {
1323+
// @ts-expect-error
13021324
const request = new NextApiRequest()
1325+
// @ts-expect-error
13031326
const response = new NextApiResponse()
13041327
const drupal = new NextDrupalPages(BASE_URL)
13051328

0 commit comments

Comments
 (0)