-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix afterInstance advices not being fired
fix #135
- Loading branch information
Showing
3 changed files
with
78 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,90 @@ | ||
import { beforeMethod, afterMethod, afterInstance, beforeInstance } from "../src" | ||
|
||
const op1 = meta => meta.args[0]++ | ||
const op2 = meta => meta.args[0] *= 2 | ||
const op3 = meta => meta.args[0] -= 5 | ||
const op4 = meta => meta.args[0] *= 10 | ||
const op5 = meta => meta.args[0] /= 2 | ||
const op1 = meta => meta.args[0].push("op1") | ||
const op2 = meta => meta.args[0].push("op2") | ||
const op3 = meta => meta.args[0].push("op3") | ||
const op4 = meta => meta.args[0].push("op4") | ||
const op5 = meta => meta.args[0].push("op5") | ||
|
||
@beforeInstance(op2) | ||
@beforeInstance(op1) | ||
@beforeInstance(op5) | ||
class Dummy1 { | ||
output | ||
constructor (arg) { | ||
this.output = arg | ||
} | ||
constructor(a) {} | ||
} | ||
|
||
@beforeInstance(op2, op1, op5) | ||
class Dummy2 { | ||
output | ||
constructor (arg) { | ||
this.output = arg | ||
} | ||
constructor(a) {} | ||
} | ||
|
||
class Dummy3 { | ||
@beforeMethod(op3, op5, op1) | ||
static someMethod (arg) { | ||
return arg | ||
} | ||
static someMethod (a) {} | ||
} | ||
|
||
class Dummy4 { | ||
@beforeMethod(op3) | ||
@beforeMethod(op5) | ||
@beforeMethod(op1) | ||
static someMethod (arg) { | ||
return arg | ||
} | ||
static someMethod (a) {} | ||
} | ||
|
||
@afterInstance(op4) | ||
@afterInstance(op5) | ||
@afterInstance(op1) | ||
class Dummy5 { | ||
output | ||
constructor (arg) { | ||
this.output = arg | ||
} | ||
constructor(a) {} | ||
} | ||
|
||
@afterInstance(op4, op5, op1) | ||
class Dummy6 { | ||
output | ||
constructor (arg) { | ||
this.output = arg | ||
} | ||
constructor(a) {} | ||
} | ||
|
||
class Dummy7 { | ||
@afterMethod(op2, op5, op3) | ||
static someMethod (arg) { | ||
return arg | ||
} | ||
static someMethod (a) {} | ||
} | ||
|
||
class Dummy8 { | ||
@afterMethod(op2) | ||
@afterMethod(op5) | ||
@afterMethod(op3) | ||
static someMethod (arg) { | ||
return arg | ||
} | ||
static someMethod (a) {} | ||
} | ||
|
||
describe("obtain several product by doing calculation to ensure advice order", () => { | ||
it("evaluate before instance order", () => { | ||
const instance1 = new Dummy1(0) | ||
const instance2 = new Dummy2(0) | ||
expect(instance1.output).toEqual(instance2.output) | ||
const r1 = [] | ||
const r2 = [] | ||
new Dummy1(r1) | ||
new Dummy2(r2) | ||
expect(r1.join()).toEqual(r2.join()) | ||
expect(r1.join()).toEqual("op2,op1,op5") | ||
}) | ||
it("evaluate after instance order", () => { | ||
const instance5 = new Dummy5(0) | ||
const instance6 = new Dummy6(0) | ||
expect(instance5.output).toEqual(instance6.output) | ||
const r1 = [] | ||
const r2 = [] | ||
new Dummy5(r1) | ||
new Dummy6(r2) | ||
expect(r1.join()).toEqual(r2.join()) | ||
expect(r1.join()).toEqual("op4,op5,op1") | ||
}) | ||
it("evaluate before method order", () => { | ||
const res3 = Dummy3.someMethod(0) | ||
const res4 = Dummy4.someMethod(0) | ||
expect(res3).toEqual(res4) | ||
const r1 = [] | ||
const r2 = [] | ||
Dummy3.someMethod(r1) | ||
Dummy4.someMethod(r2) | ||
expect(r1.join()).toEqual(r2.join()) | ||
expect(r1.join()).toEqual("op3,op5,op1") | ||
}) | ||
it("evaluate after method order", () => { | ||
const res7 = Dummy7.someMethod(0) | ||
const res8 = Dummy8.someMethod(0) | ||
expect(res7).toEqual(res8) | ||
const r1 = [] | ||
const r2 = [] | ||
Dummy7.someMethod(r1) | ||
Dummy8.someMethod(r2) | ||
expect(r1.join()).toEqual(r2.join()) | ||
expect(r1.join()).toEqual("op2,op5,op3") | ||
}) | ||
}) |