Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions packages/enhance/src/stub.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,43 @@
import { describe } from "node:test";
import assert from "node:assert/strict";
import { describe, it } from "node:test";
import { enhance } from "./enhance.lib.ts";

describe("Stub", () => {});
describe("enhance", () => {
it("enhances objects with custom methods", () => {
const base = { value: 1 };
const enhanced = enhance("numbers", base, {
double: function () {
return this.value * 2;
},
add: function (n: number) {
return this.value + n;
},
});

assert.equal(enhanced.double(), 2);
assert.equal(enhanced.add(3), 4);
assert.strictEqual(enhanced.$(), base);
});

it("does not mutate the original object when enhanced again", () => {
const base = { value: 1 };
const first = enhance("numbers", base, {
inc: function () {
return this.value + 1;
},
});

const second = enhance("numbers", first, {
double: function () {
return this.value * 2;
},
});

assert.equal(typeof (first as any).double, "undefined");
assert.deepEqual(base, { value: 1 });
assert.equal(first.inc(), 2);
assert.equal(second.double(), 2);
assert.strictEqual(first.$(), base);
assert.strictEqual(second.$().$(), base);
});
});
Loading