-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc7b951
commit af943bb
Showing
11 changed files
with
137 additions
and
376 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { each } from '../configs/each.js'; | ||
|
||
export async function test(cb: () => Promise<unknown>): Promise<void>; | ||
export function test(cb: () => unknown): void; | ||
export async function test( | ||
cb: () => unknown | Promise<unknown> | ||
): Promise<void> { | ||
if (typeof each.before.cb === 'function' && each.before.test) { | ||
const beforeResult = each.before.cb(); | ||
if (beforeResult instanceof Promise) await beforeResult; | ||
} | ||
|
||
const resultCb = cb(); | ||
if (resultCb instanceof Promise) await resultCb; | ||
|
||
if (typeof each.after.cb === 'function' && each.after.test) { | ||
const afterResult = each.after.cb(); | ||
if (afterResult instanceof Promise) await afterResult; | ||
} | ||
} |
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,5 +1,5 @@ | ||
--- | ||
sidebar_position: 3 | ||
sidebar_position: 4 | ||
--- | ||
|
||
# log | ||
|
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,66 @@ | ||
--- | ||
sidebar_position: 3 | ||
--- | ||
|
||
# test | ||
|
||
> `test(() => void)` | ||
`test` is a helper to assist you in such cases: | ||
|
||
- Use the beforeEach and afterEach for each `test` performed | ||
- Isolate or group your tests in the same file | ||
|
||
```ts | ||
import { test, beforeEach, afterEach } from 'poku'; | ||
|
||
const prepareService = () => true; | ||
const resetService = () => true; | ||
|
||
beforeEach(() => prepareService(), { | ||
assert: false, | ||
}); | ||
|
||
afterEach(() => resetService(), { | ||
assert: false, | ||
}); | ||
|
||
test(() => { | ||
// do anything you want | ||
}); | ||
|
||
test(() => { | ||
// do anything you want | ||
}); | ||
``` | ||
|
||
:::info | ||
Ensure you disabled the assert on **beforeEach** and **afterEach**. | ||
::: | ||
|
||
## By using promises | ||
|
||
```ts | ||
import { test, beforeEach, afterEach } from 'poku'; | ||
|
||
const prepareService = () => | ||
new Promise((resolve) => resolve(true), { | ||
assert: false, | ||
}); | ||
|
||
const resetService = () => | ||
new Promise((resolve) => resolve(true), { | ||
assert: false, | ||
}); | ||
|
||
beforeEach(async () => await prepareService()); | ||
afterEach(async () => await resetService()); | ||
|
||
await test(async () => { | ||
// do anything you want | ||
}); | ||
|
||
await test(async () => { | ||
// do anything you want | ||
}); | ||
``` |
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
Oops, something went wrong.