
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
@star-unit/js
Advanced tools
A lightweight tool for instant JavaScript unit testing.
npm install @star-unit/js
Initialize configuration:
npx suj init
Run tests:
npx suj test
Note: After installation, the CLI is available via the
suj
command.
describe
, test
, expect
)..not
negations.init
Initialize the configuration required by this tool.
Options:
-r, --root <root>
โ Path to the root directory (default: "./"
).-e, --ext <root>
โ Test file extension (default: "test.js"
).test
Run unit tests.
Options:
describe(description, fn)
Groups related tests together.
describe("Math operations", () => {
// tests here
});
test(description, fn)
Defines a single unit test.
test("adds numbers correctly", () => {
const result = 1 + 2;
expect(result).toBe(3);
});
expect(actual)
Starts an assertion chain for a test result.
expect(4).toBe(4);
expect(4).not.toBe(5);
You can chain .not
to invert the matcher logic.
Matchers are used to assert specific conditions. Each matcher has a .not
version that inverts its logic.
Matcher | Description | .not Version |
---|---|---|
.toBe(expected) | Value is exactly equal (=== ) | Value is not exactly equal |
.toEqual(expected) | Values are deeply equal | Values are not deeply equal |
.toThrow(expected?) | Function throws error | Function does not throw |
.toBeGreaterThan(expected) | Greater than comparison | Not greater than |
.toBeLessThan(expected) | Less than comparison | Not less than |
.toBeNull() | Value is null | Value is not null |
.toBeTruthy() | Value is truthy (!!value === true ) | Value is not truthy |
const { describe, test, expect } = require("@star-unit/js");
describe("Array methods", () => {
test("push adds an item", () => {
const arr = [];
arr.push(1);
expect(arr.length).toBe(1);
expect(arr[0]).toBe(1);
});
test("pop removes the last item", () => {
const arr = [1, 2, 3];
const last = arr.pop();
expect(last).toBe(3);
expect(arr.length).toBe(2);
});
test("pop should not add elements", () => {
const arr = [1, 2, 3];
arr.pop();
expect(arr.length).not.toBe(3);
});
});
ISC License.
FAQs
> A lightweight tool for instant JavaScript unit testing.
We found that @star-unit/js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.ย It has 1 open source maintainer 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.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.