2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-07-13 07:04:30 +00:00
|
|
|
import {
|
|
|
|
assert,
|
|
|
|
assertEquals,
|
|
|
|
AssertionError,
|
|
|
|
assertStringIncludes,
|
2024-05-07 00:08:16 +00:00
|
|
|
assertThrows,
|
2023-07-13 07:04:30 +00:00
|
|
|
} from "./mod.ts";
|
|
|
|
|
2024-05-07 00:08:16 +00:00
|
|
|
Deno.test("assertStringIncludes()", () => {
|
2023-07-13 07:04:30 +00:00
|
|
|
assertStringIncludes("Denosaurus", "saur");
|
|
|
|
assertStringIncludes("Denosaurus", "Deno");
|
|
|
|
assertStringIncludes("Denosaurus", "rus");
|
|
|
|
let didThrow;
|
|
|
|
try {
|
|
|
|
assertStringIncludes("Denosaurus", "Raptor");
|
|
|
|
didThrow = false;
|
|
|
|
} catch (e) {
|
|
|
|
assert(e instanceof AssertionError);
|
|
|
|
didThrow = true;
|
|
|
|
}
|
|
|
|
assertEquals(didThrow, true);
|
|
|
|
});
|
|
|
|
|
2024-05-07 00:08:16 +00:00
|
|
|
Deno.test("assertStringIncludes() throws", () => {
|
|
|
|
assertThrows(
|
|
|
|
() => assertStringIncludes("Denosaurus from Jurassic", "Raptor"),
|
|
|
|
AssertionError,
|
|
|
|
`Expected actual: "Denosaurus from Jurassic" to contain: "Raptor".`,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test("assertStringIncludes() with custom message", () => {
|
|
|
|
assertThrows(
|
|
|
|
() =>
|
|
|
|
assertStringIncludes(
|
|
|
|
"Denosaurus from Jurassic",
|
|
|
|
"Raptor",
|
|
|
|
"CUSTOM MESSAGE",
|
|
|
|
),
|
|
|
|
AssertionError,
|
|
|
|
`Expected actual: "Denosaurus from Jurassic" to contain: "Raptor": CUSTOM MESSAGE`,
|
|
|
|
);
|
2023-07-13 07:04:30 +00:00
|
|
|
});
|