Skip to content

Commit 70d3d22

Browse files
authored
chore: Replace assertThrowsAsync with assertRejects (#248)
1 parent f6e2409 commit 70d3d22

5 files changed

Lines changed: 17 additions & 16 deletions

File tree

tests/client_test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { delay } from "../vendor/https/deno.land/std/async/delay.ts";
33
import {
44
assert,
55
assertEquals,
6-
assertThrowsAsync,
6+
assertRejects,
77
} from "../vendor/https/deno.land/std/testing/asserts.ts";
88
import {
99
newClient,
@@ -42,7 +42,7 @@ suite.test("client caching with opt out", async () => {
4242
});
4343

4444
suite.test("client caching without opt in or opt out", async () => {
45-
await assertThrowsAsync(
45+
await assertRejects(
4646
() => {
4747
return client.clientCaching("YES");
4848
},
@@ -130,7 +130,7 @@ suite.test("client list", async () => {
130130
list = await client.clientList({ ids: [id] });
131131
assert(list!.includes(`id=${id}`));
132132

133-
await assertThrowsAsync(
133+
await assertRejects(
134134
() => {
135135
return client.clientList({ type: "MASTER", ids: [id] });
136136
},
@@ -157,7 +157,7 @@ suite.test("client tracking", async () => {
157157
}),
158158
"OK",
159159
);
160-
await assertThrowsAsync(
160+
await assertRejects(
161161
() => {
162162
return client.clientTracking({ mode: "ON", bcast: true, optIn: true });
163163
},
@@ -194,13 +194,14 @@ suite.test("client unblock with error", async () => {
194194
const tempClient = await newClient({ hostname: "127.0.0.1", port });
195195
try {
196196
const id = await tempClient.clientID();
197-
assertThrowsAsync(
197+
const promise = assertRejects(
198198
() => tempClient.brpop(0, "key1"),
199199
Error,
200200
"-UNBLOCKED",
201201
);
202202
await delay(5); // Give some leeway for brpop to reach redis.
203203
assertEquals(await client.clientUnblock(id, "ERROR"), 1);
204+
await promise;
204205
} finally {
205206
tempClient.close();
206207
}

tests/cluster/test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
assert,
66
assertArrayIncludes,
77
assertEquals,
8-
assertThrowsAsync,
8+
assertRejects,
99
} from "../../vendor/https/deno.land/std/testing/asserts.ts";
1010
import sample from "../../vendor/https/cdn.skypack.dev/lodash-es/sample.js";
1111
import calculateSlot from "../../vendor/https/cdn.skypack.dev/cluster-key-slot/lib/index.js";
@@ -40,7 +40,7 @@ suite.test("del multiple keys in the same hash slot", async () => {
4040
suite.test("del multiple keys in different hash slots", async () => {
4141
await client.set("foo", "a");
4242
await client.set("bar", "b");
43-
await assertThrowsAsync(
43+
await assertRejects(
4444
async () => {
4545
await client.del("foo", "bar");
4646
},
@@ -186,7 +186,7 @@ suite.test("properly handle too many redirections", async () => {
186186
},
187187
});
188188
try {
189-
await assertThrowsAsync(
189+
await assertRejects(
190190
() => client.get("foo"),
191191
Error,
192192
"Too many Cluster redirections?",

tests/general_test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ErrorReplyError, parseURL } from "../mod.ts";
22
import {
33
assertEquals,
4-
assertThrowsAsync,
4+
assertRejects,
55
} from "../vendor/https/deno.land/std/testing/asserts.ts";
66
import {
77
newClient,
@@ -52,7 +52,7 @@ suite.test("db0", async () => {
5252
});
5353

5454
suite.test("connect with wrong password", async () => {
55-
await assertThrowsAsync(async () => {
55+
await assertRejects(async () => {
5656
await newClient({
5757
hostname: "127.0.0.1",
5858
port,
@@ -63,7 +63,7 @@ suite.test("connect with wrong password", async () => {
6363

6464
suite.test("connect with empty password", async () => {
6565
// In Redis, authentication with an empty password will always fail.
66-
await assertThrowsAsync(async () => {
66+
await assertRejects(async () => {
6767
await newClient({
6868
hostname: "127.0.0.1",
6969
port,
@@ -87,7 +87,7 @@ suite.test("exists", async () => {
8787

8888
[Infinity, NaN, "", "port"].forEach((v) => {
8989
suite.test(`invalid port: ${v}`, async () => {
90-
await assertThrowsAsync(
90+
await assertRejects(
9191
async () => {
9292
await newClient({ hostname: "127.0.0.1", port: v });
9393
},

tests/pubsub_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { delay } from "../vendor/https/deno.land/std/async/delay.ts";
22
import {
33
assert,
44
assertEquals,
5-
assertThrowsAsync,
5+
assertRejects,
66
} from "../vendor/https/deno.land/std/testing/asserts.ts";
77
import {
88
newClient,
@@ -48,7 +48,7 @@ suite.test("testSubscribe2", async () => {
4848
assertEquals(sub.isClosed, true);
4949
assertEquals(client.isClosed, true);
5050
pub.close();
51-
await assertThrowsAsync(async () => {
51+
await assertRejects(async () => {
5252
await client.get("aaa");
5353
}, Deno.errors.BadResource);
5454
});

tests/stream_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
assert,
66
assertEquals,
77
assertNotEquals,
8-
assertThrowsAsync,
8+
assertRejects,
99
} from "../vendor/https/deno.land/std/testing/asserts.ts";
1010
import {
1111
newClient,
@@ -196,7 +196,7 @@ suite.test("xgroup create and destroy", async () => {
196196

197197
const created = await client.xgroupCreate(key, groupName, "$", true);
198198
assertEquals(created, "OK");
199-
await assertThrowsAsync(
199+
await assertRejects(
200200
async () => {
201201
await client.xgroupCreate(key, groupName, 0, true);
202202
},

0 commit comments

Comments
 (0)