-
Notifications
You must be signed in to change notification settings - Fork 37
/
pointcut.spec.ts
59 lines (54 loc) · 1.38 KB
/
pointcut.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
import { Pointcut, Precondition, JointPoint, Advice } from '../../lib/src/core';
import { expect } from 'chai';
class SimpleJP extends JointPoint {
match(descriptor: Object): string[] {
if (this.precondition.assert(descriptor)) {
return ['1'];
}
return [];
}
getTarget(fn: any): any {
return '42';
}
woveTarget(fn: any, match: any, advice: Advice): void {}
wove() {}
}
class SimplePrecondition implements Precondition {
assert(data: any): boolean {
return true;
}
}
// TODO(mgechev) refactor with spies
describe('Pointcut', () => {
let pc: Pointcut;
let jp1: JointPoint;
let jp2: JointPoint;
beforeEach(() => {
pc = new Pointcut();
jp1 = new SimpleJP(new SimplePrecondition());
jp1.precondition = new SimplePrecondition();
jp2 = new SimpleJP(new SimplePrecondition());
jp2.precondition = new SimplePrecondition();
pc.joinPoints = [jp1, jp2];
});
it('Match should be invoked', done => {
let bak = jp1.match;
let called1 = false;
jp1.match = function(d): any[] {
bak.call(this, d);
called1 = true;
return [];
};
let bak2 = jp1.match;
let called2 = false;
jp2.match = function(d): any[] {
bak2.call(this, d);
called2 = true;
return [];
};
pc.apply(function() {}, null);
expect(called1).to.equal(true);
expect(called2).to.equal(true);
done();
});
});