rc-js-util
Version:
A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.
55 lines (45 loc) • 1.05 kB
text/typescript
import { Once } from "./once.js";
import { Test_setDefaultFlags } from "../test-util/test_set-default-flags.js";
describe("=> once decorator", () =>
{
beforeEach(() =>
{
Test_setDefaultFlags();
});
let argTestRan = false;
class Test
{
public constructor
(
private v: number,
)
{
}
public increment()
{
return ++this.v;
}
public argumentTest(a: number, b: number)
{
expect(a).toBe(1);
expect(b).toBe(2);
argTestRan = true;
}
}
const t1 = new Test(0);
it("| runs the method only once", () =>
{
expect(t1.increment()).toBe(1);
expect(t1.increment()).toBe(1);
const t2 = new Test(10);
expect(t2.increment()).toBe(11);
expect(t2.increment()).toBe(11);
});
it("| proxies arguments", () =>
{
t1.argumentTest(1, 2);
expect(argTestRan).toBeTrue();
});
});