1 |
import Callable from "@framework/functions/Callable"; |
2 |
import { beforeEach, describe, expect, it } from "vitest"; |
3 |
|
4 |
describe("Callable", () => { |
5 |
let MyObject: new () => Callable; |
6 |
let callable: Callable; |
7 |
|
8 |
beforeEach(() => { |
9 |
MyObject = class MyObject extends Callable { |
10 |
protected invoke(...args: number[]) { |
11 |
return args.reduce((a, b) => a + b, 0); |
12 |
} |
13 |
}; |
14 |
|
15 |
callable = new MyObject(); |
16 |
}); |
17 |
|
18 |
it("should create a callable object", () => { |
19 |
expect(callable).toBeInstanceOf(Function); |
20 |
expect(callable(1, 2, 5)).toBe(8); |
21 |
}); |
22 |
|
23 |
it("should return the correct name", () => { |
24 |
expect(callable.toString()).toBe("MyObject"); |
25 |
expect(callable[Symbol.toStringTag]()).toBe("MyObject"); |
26 |
}); |
27 |
|
28 |
it("should be callable with other methods", () => { |
29 |
expect(callable(1, 2, 5)).toBe(8); |
30 |
expect(callable.call(null, 1, 2, 5)).toBe(8); |
31 |
expect(callable.apply(null, [1, 2, 5])).toBe(8); |
32 |
}); |
33 |
}); |