-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
function.spec.ts
110 lines (93 loc) · 3.26 KB
/
function.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import reflect from "@plumier/reflect"
describe("Reflect function", () => {
it("Should reflect function", () => {
function myFunction() { }
const meta = reflect(myFunction)
expect(meta).toMatchSnapshot()
})
it("Should able to reflect function parameter names", () => {
function myFunction(par1: number, par2: number) { }
const meta = reflect(myFunction)
expect(meta).toMatchSnapshot()
})
it("Should able to reflect destructured parameter", () => {
interface Parameter { prop1: number, prop2: number }
function myFunction({ prop1, prop2 }: Parameter) { }
const meta = reflect(myFunction)
expect(meta).toMatchSnapshot()
})
it("Should able to reflect rest parameter", () => {
function myFunction(par1: number, ...par2: number[]) { }
const meta = reflect(myFunction)
expect(meta).toMatchSnapshot()
})
it("Should able to reflect function inside object", () => {
const obj = {
fn(par1: string) { }
}
const meta = reflect(obj.fn)
expect(meta).toMatchSnapshot()
})
it("Should able to reflect async function inside object", () => {
const obj = {
async fn(par1: string) { }
}
const meta = reflect(obj.fn)
expect(meta).toMatchSnapshot()
})
it("Should able to reflect function property inside object", () => {
const obj = {
fn: function (par1: string) { }
}
const meta = reflect(obj.fn)
expect(meta).toMatchSnapshot()
})
it("Should able to reflect async function property inside object", () => {
const obj = {
fn: async function (par1: string) { }
}
const meta = reflect(obj.fn)
expect(meta).toMatchSnapshot()
})
it("Should able to reflect lambda function inside object", () => {
const obj = {
fn: (par1: number) => {
return par1
},
};
const metadata = reflect(obj.fn);
expect(metadata).toMatchSnapshot()
})
it("Should able to reflect lambda function inside object", () => {
const obj = {
fn: async (par1: number) => {
return par1
},
};
const metadata = reflect(obj.fn);
expect(metadata).toMatchSnapshot()
})
})
describe("Reflect lambda function", () => {
it("Should reflect function", () => {
const myFunction = () => { }
const meta = reflect(myFunction)
expect(meta).toMatchSnapshot()
})
it("Should able to reflect function parameter names", () => {
const myFunction = (par1: number, par2: number) => { }
const meta = reflect(myFunction)
expect(meta).toMatchSnapshot()
})
it("Should able to reflect destructured parameter", () => {
interface Parameter { prop1: number, prop2: number }
const myFunction = ({ prop1, prop2 }: Parameter) => { }
const meta = reflect(myFunction)
expect(meta).toMatchSnapshot()
})
it("Should able to reflect rest parameter", () => {
const myFunction = (par1: number, ...par2: number[]) => { }
const meta = reflect(myFunction)
expect(meta).toMatchSnapshot()
})
})