Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@clipboard-health/testing-core
Advanced tools
TypeScript-friendly testing utilities.
npm install @clipboard-health/testing-core
expect
helpersJest's expect(...).toBeDefined()
does not narrow types.
This gives a type error:
const value = getValue(); // returns 'string | undefined'
expect(value).toBeDefined();
const { length } = value;
// ^? Property 'length' does not exist on type 'string | undefined'.
This library's helpers narrow types:
import { ok } from "node:assert/strict";
import { expectToBeDefined } from "@clipboard-health/testing-core";
function getValue(): string | undefined {
return "hi";
}
const value = getValue();
expectToBeDefined(value);
// Narrowed to `string`
const { length } = value;
ok(length === 2);
import { ok } from "node:assert/strict";
import { expectToBeLeft } from "@clipboard-health/testing-core";
import { either as E } from "@clipboard-health/util-ts";
function divide(numerator: number, denominator: number): E.Either<string, number> {
if (denominator === 0) {
return E.left("Cannot divide by zero");
}
return E.right(numerator / denominator);
}
const value = divide(10, 0);
expectToBeLeft(value);
// Narrowed to Left
ok(value.left === "Cannot divide by zero");
import { ok } from "node:assert/strict";
import { expectToBeRight } from "@clipboard-health/testing-core";
import { either as E } from "@clipboard-health/util-ts";
function divide(numerator: number, denominator: number): E.Either<string, number> {
if (denominator === 0) {
return E.left("Cannot divide by zero");
}
return E.right(numerator / denominator);
}
const value = divide(10, 2);
expectToBeRight(value);
// Narrowed to Right
ok(value.right === 5);
import { ok } from "node:assert/strict";
import { expectToBeDefined, expectToBeSafeParseError } from "@clipboard-health/testing-core";
import { z } from "zod";
const schema = z.object({ name: z.string() });
const value = schema.safeParse({ name: 1 });
expectToBeSafeParseError(value);
// Narrowed to `SafeParseError`
const firstIssue = value.error.issues[0];
expectToBeDefined(firstIssue);
// Narrowed to `ZodIssue`
ok(firstIssue.message === "Expected string, received number");
import { ok } from "node:assert/strict";
import { expectToBeSafeParseSuccess } from "@clipboard-health/testing-core";
import { z } from "zod";
const schema = z.object({ name: z.string() });
const value = schema.safeParse({ name: "hi" });
expectToBeSafeParseSuccess(value);
// Narrowed to `SafeParseSuccess`
ok(value.data.name === "hi");
See package.json
scripts
for a list of commands.
FAQs
TypeScript-friendly testing utilities.
The npm package @clipboard-health/testing-core receives a total of 22 weekly downloads. As such, @clipboard-health/testing-core popularity was classified as not popular.
We found that @clipboard-health/testing-core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.