-
Notifications
You must be signed in to change notification settings - Fork 614
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(assert): improve test coverage (#4679)
* test(assert): improve test coverage * chore: format * chore: lint * nits --------- Co-authored-by: Asher Gomez <[email protected]>
- Loading branch information
Showing
25 changed files
with
394 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,28 @@ | ||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. | ||
import { assert, AssertionError, assertMatch } from "./mod.ts"; | ||
import { assertThrows } from "./assert_throws.ts"; | ||
import { AssertionError, assertMatch } from "./mod.ts"; | ||
|
||
Deno.test("AssertStringMatching", function () { | ||
Deno.test("assertMatch()", () => { | ||
assertMatch("[email protected]", RegExp(/[a-zA-Z]+@[a-zA-Z]+.com/)); | ||
}); | ||
|
||
Deno.test("AssertStringMatchingThrows", function () { | ||
let didThrow = false; | ||
try { | ||
assertMatch("Denosaurus from Jurassic", RegExp(/Raptor/)); | ||
} catch (e) { | ||
assert(e instanceof AssertionError); | ||
assert( | ||
e.message === | ||
`Expected actual: "Denosaurus from Jurassic" to match: "/Raptor/".`, | ||
); | ||
didThrow = true; | ||
} | ||
assert(didThrow); | ||
Deno.test("assertMatch() throws", () => { | ||
assertThrows( | ||
() => assertMatch("Denosaurus from Jurassic", RegExp(/Raptor/)), | ||
AssertionError, | ||
`Expected actual: "Denosaurus from Jurassic" to match: "/Raptor/".`, | ||
); | ||
}); | ||
|
||
Deno.test("assertMatch() throws with custom message", () => { | ||
assertThrows( | ||
() => | ||
assertMatch( | ||
"Denosaurus from Jurassic", | ||
RegExp(/Raptor/), | ||
"CUSTOM MESSAGE", | ||
), | ||
AssertionError, | ||
`Expected actual: "Denosaurus from Jurassic" to match: "/Raptor/": CUSTOM MESSAGE`, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,46 @@ | ||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. | ||
import { | ||
assert, | ||
assertEquals, | ||
AssertionError, | ||
assertNotEquals, | ||
} from "./mod.ts"; | ||
import { AssertionError, assertNotEquals, assertThrows } from "./mod.ts"; | ||
import { stub } from "@std/testing/mock"; | ||
|
||
Deno.test("NotEquals", function () { | ||
const a = { foo: "bar" }; | ||
const b = { bar: "foo" }; | ||
assertNotEquals<unknown>(a, b); | ||
Deno.test("assertNotEquals()", () => { | ||
assertNotEquals<unknown>({ foo: "bar" }, { bar: "foo" }); | ||
assertNotEquals("Denosaurus", "Tyrannosaurus"); | ||
assertNotEquals( | ||
new Date(2019, 0, 3, 4, 20, 1, 10), | ||
new Date(2019, 0, 3, 4, 20, 1, 20), | ||
); | ||
assertNotEquals(new Date("invalid"), new Date(2019, 0, 3, 4, 20, 1, 20)); | ||
let didThrow; | ||
try { | ||
assertNotEquals("Raptor", "Raptor"); | ||
didThrow = false; | ||
} catch (e) { | ||
assert(e instanceof AssertionError); | ||
didThrow = true; | ||
} | ||
assertEquals(didThrow, true); | ||
}); | ||
|
||
Deno.test("assertNotEquals() throws", () => { | ||
assertThrows( | ||
() => { | ||
assertNotEquals("foo", "foo"); | ||
}, | ||
AssertionError, | ||
"Expected actual: foo not to be: foo.", | ||
); | ||
}); | ||
|
||
Deno.test("assertNotEquals() throws with custom message", () => { | ||
assertThrows( | ||
() => { | ||
assertNotEquals("foo", "foo", "CUSTOM MESSAGE"); | ||
}, | ||
AssertionError, | ||
"Expected actual: foo not to be: foo: CUSTOM MESSAGE", | ||
); | ||
}); | ||
|
||
Deno.test("assertNotEquals() throws with [Cannot display]", () => { | ||
using _ = stub(globalThis, "String", () => { | ||
throw new Error(); | ||
}); | ||
assertThrows( | ||
() => { | ||
assertNotEquals("a", "a"); | ||
}, | ||
AssertionError, | ||
`Expected actual: [Cannot display] not to be: [Cannot display].`, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,33 @@ | ||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. | ||
import { assertNotInstanceOf } from "./mod.ts"; | ||
import { AssertionError, assertNotInstanceOf, assertThrows } from "./mod.ts"; | ||
|
||
Deno.test({ | ||
name: "assertNotInstanceOf", | ||
name: "assertNotInstanceOf()", | ||
fn() { | ||
assertNotInstanceOf("not a number", Number); | ||
assertNotInstanceOf(42, String); | ||
assertNotInstanceOf(new URL("http://example.com"), Boolean); | ||
}, | ||
}); | ||
|
||
Deno.test({ | ||
name: "assertNotInstanceOf() throws", | ||
fn() { | ||
assertThrows( | ||
() => assertNotInstanceOf(new Date(), Date), | ||
AssertionError, | ||
'Expected object to not be an instance of "function".', | ||
); | ||
}, | ||
}); | ||
|
||
Deno.test({ | ||
name: "assertNotInstanceOf() throws with custom message", | ||
fn() { | ||
assertThrows( | ||
() => assertNotInstanceOf(new Date(), Date, "CUSTOM MESSAGE"), | ||
AssertionError, | ||
'Expected object to not be an instance of "function": CUSTOM MESSAGE', | ||
); | ||
}, | ||
}); |
Oops, something went wrong.