-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(modifier): add
number
pre modifier
- Loading branch information
1 parent
1d61e93
commit 8ce5f1e
Showing
6 changed files
with
99 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2021-Present the Unitest authors. All rights reserved. MIT license. | ||
// This module is browser compatible. | ||
|
||
import type { PreModifier } from "./types.ts"; | ||
|
||
/** Use `.number` to convert any `actual` to `number`. Internally, the `Number` | ||
* constructor is used. | ||
* ```ts | ||
* import { | ||
* defineExpect, | ||
* number, | ||
* test, | ||
* toBe, | ||
* } from "https://deno.land/x/unitest@$VERSION/mod.ts"; | ||
* | ||
* const expect = defineExpect({ | ||
* matcherMap: { | ||
* toBe, | ||
* }, | ||
* modifierMap: { | ||
* number, | ||
* }, | ||
* }); | ||
* | ||
* test("passes when numberized value to be", () => { | ||
* expect("").number.toBe(0); | ||
* expect("test").number.toBe(NaN); | ||
* }); | ||
* ``` | ||
*/ | ||
const number: PreModifier<unknown, { actual: number }> = { | ||
type: "pre", | ||
fn: (actual) => ({ actual: Number(actual) }), | ||
}; | ||
|
||
export { number }; |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2021-Present the Unitest authors. All rights reserved. MIT license. | ||
|
||
import { number } from "./number.ts"; | ||
import { assertEquals } from "../dev_deps.ts"; | ||
import type { PreModifierContext } from "./types.ts"; | ||
|
||
Deno.test("number", () => { | ||
const context = {} as PreModifierContext; | ||
assertEquals(number.type, "pre"); | ||
assertEquals(number.fn("", context), { actual: 0 }); | ||
assertEquals(number.fn("test", context), { actual: NaN }); | ||
assertEquals(number.fn(1, context), { actual: 1 }); | ||
assertEquals(number.fn(1n, context), { actual: 1 }); | ||
}); |