-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f09dec
commit 814080c
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { describe, it, expect } from "vitest"; | ||
|
||
function logAround(_target: any, key: string, descriptor: PropertyDescriptor) { | ||
const originalMethod = descriptor.value; | ||
|
||
descriptor.value = function (...args: any[]) { | ||
console.log(`Before calling ${key}`); | ||
const result = originalMethod.apply(this, args); | ||
console.log(`After calling ${key}`); | ||
return result; | ||
}; | ||
|
||
return descriptor; | ||
} | ||
|
||
function addOne(_target: any, _key: string, descriptor: PropertyDescriptor) { | ||
const originalMethod = descriptor.value; | ||
|
||
descriptor.value = function (...args: any[]) { | ||
const result = originalMethod.apply(this, args); | ||
return result + 1; | ||
}; | ||
|
||
return descriptor; | ||
} | ||
|
||
export class TestClass { | ||
@logAround | ||
hello() { | ||
console.log("Hello, world!"); | ||
} | ||
|
||
@addOne | ||
add(a: number, b: number) { | ||
return a + b; | ||
} | ||
} | ||
|
||
describe("deco.test.tsx", () => { | ||
// it("should pass", () => { | ||
// const testClass = new TestClass(); | ||
// testClass.hello(); | ||
// }); | ||
it("should add one", () => { | ||
const testClass = new TestClass(); | ||
const result = testClass.add(2, 3); | ||
expect(result).toBe(6); | ||
}); | ||
}); |