/[sudobot]/trunk/tests/framework/functions/Callable.test.ts
ViewVC logotype

Annotation of /trunk/tests/framework/functions/Callable.test.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 575 - (hide annotations)
Mon Jul 29 17:59:26 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 1014 byte(s)
chore: add trunk
1 rakinar2 575 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     });

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26