Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
offer aspectj-like around advice via new MethodMetadata.complete meth…
…od (#76) * offer aspectj-like around advice via new MethodMetadata.complete method * bump minor (to 0.8.0) * add test * fix typo * update package-lock.json
- Loading branch information
1 parent
a58040b
commit 1c03a12
Showing
6 changed files
with
58 additions
and
8 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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,33 @@ | ||
import { Wove, resetRegistry, Metadata } from "../../lib/src/core"; | ||
|
||
import { expect } from "chai"; | ||
import { aroundMethod } from "../../lib"; | ||
|
||
describe("around advices", () => { | ||
afterEach(() => { | ||
resetRegistry(); | ||
}); | ||
|
||
it("should only get invoked once when using MethodMetadata.complete()", () => { | ||
let count = 0; | ||
|
||
class Aspect { | ||
@aroundMethod({ classNamePattern: /^Test/, methodNamePattern: /^get$/ }) | ||
aroundMethod(meta: Metadata) { | ||
return meta.method.complete(...meta.method.args) + " appended from the aspect"; | ||
} | ||
} | ||
|
||
@Wove() | ||
class Test { | ||
get(it: string): string { | ||
count++; | ||
return it; | ||
} | ||
} | ||
|
||
const test = new Test(); | ||
expect(test.get("test")).to.equal("test appended from the aspect"); | ||
expect(count).to.equal(1); | ||
}); | ||
}); |