Skip to content

Commit

Permalink
chore: Replace assertThrowsAsync with assertRejects (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
uki00a authored Aug 15, 2021
1 parent f6e2409 commit 70d3d22
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
11 changes: 6 additions & 5 deletions tests/client_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { delay } from "../vendor/https/deno.land/std/async/delay.ts";
import {
assert,
assertEquals,
assertThrowsAsync,
assertRejects,
} from "../vendor/https/deno.land/std/testing/asserts.ts";
import {
newClient,
Expand Down Expand Up @@ -42,7 +42,7 @@ suite.test("client caching with opt out", async () => {
});

suite.test("client caching without opt in or opt out", async () => {
await assertThrowsAsync(
await assertRejects(
() => {
return client.clientCaching("YES");
},
Expand Down Expand Up @@ -130,7 +130,7 @@ suite.test("client list", async () => {
list = await client.clientList({ ids: [id] });
assert(list!.includes(`id=${id}`));

await assertThrowsAsync(
await assertRejects(
() => {
return client.clientList({ type: "MASTER", ids: [id] });
},
Expand All @@ -157,7 +157,7 @@ suite.test("client tracking", async () => {
}),
"OK",
);
await assertThrowsAsync(
await assertRejects(
() => {
return client.clientTracking({ mode: "ON", bcast: true, optIn: true });
},
Expand Down Expand Up @@ -194,13 +194,14 @@ suite.test("client unblock with error", async () => {
const tempClient = await newClient({ hostname: "127.0.0.1", port });
try {
const id = await tempClient.clientID();
assertThrowsAsync(
const promise = assertRejects(
() => tempClient.brpop(0, "key1"),
Error,
"-UNBLOCKED",
);
await delay(5); // Give some leeway for brpop to reach redis.
assertEquals(await client.clientUnblock(id, "ERROR"), 1);
await promise;
} finally {
tempClient.close();
}
Expand Down
6 changes: 3 additions & 3 deletions tests/cluster/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
assert,
assertArrayIncludes,
assertEquals,
assertThrowsAsync,
assertRejects,
} from "../../vendor/https/deno.land/std/testing/asserts.ts";
import sample from "../../vendor/https/cdn.skypack.dev/lodash-es/sample.js";
import calculateSlot from "../../vendor/https/cdn.skypack.dev/cluster-key-slot/lib/index.js";
Expand Down Expand Up @@ -40,7 +40,7 @@ suite.test("del multiple keys in the same hash slot", async () => {
suite.test("del multiple keys in different hash slots", async () => {
await client.set("foo", "a");
await client.set("bar", "b");
await assertThrowsAsync(
await assertRejects(
async () => {
await client.del("foo", "bar");
},
Expand Down Expand Up @@ -186,7 +186,7 @@ suite.test("properly handle too many redirections", async () => {
},
});
try {
await assertThrowsAsync(
await assertRejects(
() => client.get("foo"),
Error,
"Too many Cluster redirections?",
Expand Down
8 changes: 4 additions & 4 deletions tests/general_test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ErrorReplyError, parseURL } from "../mod.ts";
import {
assertEquals,
assertThrowsAsync,
assertRejects,
} from "../vendor/https/deno.land/std/testing/asserts.ts";
import {
newClient,
Expand Down Expand Up @@ -52,7 +52,7 @@ suite.test("db0", async () => {
});

suite.test("connect with wrong password", async () => {
await assertThrowsAsync(async () => {
await assertRejects(async () => {
await newClient({
hostname: "127.0.0.1",
port,
Expand All @@ -63,7 +63,7 @@ suite.test("connect with wrong password", async () => {

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

[Infinity, NaN, "", "port"].forEach((v) => {
suite.test(`invalid port: ${v}`, async () => {
await assertThrowsAsync(
await assertRejects(
async () => {
await newClient({ hostname: "127.0.0.1", port: v });
},
Expand Down
4 changes: 2 additions & 2 deletions tests/pubsub_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { delay } from "../vendor/https/deno.land/std/async/delay.ts";
import {
assert,
assertEquals,
assertThrowsAsync,
assertRejects,
} from "../vendor/https/deno.land/std/testing/asserts.ts";
import {
newClient,
Expand Down Expand Up @@ -48,7 +48,7 @@ suite.test("testSubscribe2", async () => {
assertEquals(sub.isClosed, true);
assertEquals(client.isClosed, true);
pub.close();
await assertThrowsAsync(async () => {
await assertRejects(async () => {
await client.get("aaa");
}, Deno.errors.BadResource);
});
Expand Down
4 changes: 2 additions & 2 deletions tests/stream_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
assert,
assertEquals,
assertNotEquals,
assertThrowsAsync,
assertRejects,
} from "../vendor/https/deno.land/std/testing/asserts.ts";
import {
newClient,
Expand Down Expand Up @@ -196,7 +196,7 @@ suite.test("xgroup create and destroy", async () => {

const created = await client.xgroupCreate(key, groupName, "$", true);
assertEquals(created, "OK");
await assertThrowsAsync(
await assertRejects(
async () => {
await client.xgroupCreate(key, groupName, 0, true);
},
Expand Down

0 comments on commit 70d3d22

Please sign in to comment.