https://github.com/littletof/testeach
https://github.com/littletof/testeach
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/littletof/testeach
- Owner: littletof
- Created: 2020-08-04T22:08:17.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-01-06T15:33:38.000Z (over 4 years ago)
- Last Synced: 2025-02-05T00:14:07.599Z (3 months ago)
- Language: TypeScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# testEach
To make testing a lot of combinations easy.
Define the inputs and required outputs, write the test logic once, and let `testEach` run each case for you separately.
You can add descriptions to each `TestCase`, so you can use them in assertions, `async` test functions are also supported.
## Usage
```ts
import { TestCase, testEach } from "https://deno.land/x/[email protected]/mod.ts";
testEach<{a: number, b: number}, number>(
"Quick math",
[
{ input: { a: 1, b: 3 }, result: 3, desc: '1*3 should equal 3'},
{ input: { a: 2, b: 3 }, result: 6, desc: '2*3 should equal 6' },
{ input: { a: 3, b: 3 }, result: 9, desc: '3*3 should equal 9' },
{ input: { a: 4, b: 3 }, result: 12, desc: '4*3 should equal 12' },
],
(testCase) => {
assertEquals(
testCase.input.a * testCase.input.b,
testCase.result,
testCase.desc,
);
},
);testEach(
"Exceptions",
[
{ input: false, exception: { msg: "my exception" } },
{ input: 5, result: 12 },
],
(testCase) => {
if (typeof testCase.input === "number") {
assertEquals(60 / testCase.input, testCase.result);
} else {
throw new Error("my exception");
}
},
);testEach(
"Options",
[/*...*/],
(testCase) => {/* ... */ },
{only: true, ignore: true, sanitizeOps: true, sanitizeResources: true}
);```