26 lines
507 B
TypeScript
26 lines
507 B
TypeScript
import { stub } from "mock";
|
|
|
|
/**
|
|
* A shorthand for `new Uint8Array()`.
|
|
*/
|
|
export const b = (...bytes: number[]) => new Uint8Array(bytes);
|
|
|
|
/**
|
|
* @example
|
|
* Deno.test("works", stubbingWarn(() => {
|
|
* // ...
|
|
* }));
|
|
*/
|
|
export const stubbingWarn = (
|
|
fn: (t: Deno.TestContext) => void | Promise<void>,
|
|
): (t: Deno.TestContext) => Promise<void> => (
|
|
async (t) => {
|
|
const warnStub = stub(console, "warn");
|
|
try {
|
|
return await fn(t);
|
|
} finally {
|
|
warnStub.restore();
|
|
}
|
|
}
|
|
);
|