-
Notifications
You must be signed in to change notification settings - Fork 37
/
wove.spec.ts
66 lines (51 loc) · 1.42 KB
/
wove.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
import { expect } from 'chai';
import { Metadata } from './../../lib/src/core/metadata';
import { beforeMethod } from './../../lib/index';
import { Wove } from './../../lib/src/core';
import { spy } from 'sinon';
const o = 42;
@Wove()
class ClassA {
foo() {}
overridden() { return o; }
}
@Wove()
class ClassB extends ClassA {
constructor() {
super();
this.foo();
this.bar();
this.qux();
}
bar() {}
qux() {}
overridden() { return super.overridden() + 1; }
}
const methods: string[] = [];
class LoggerAspect {
@beforeMethod({
methodNamePattern: /.*/,
classNamePattern: /^ClassB|ClassA$/
})
beforeLogger(meta: Metadata) {
methods.push(meta.method.name);
}
}
describe('@Wove', () => {
beforeEach(() => (methods.length = 0));
it('should work with subclasses', () => {
const fooSpy = spy(ClassA.prototype, 'foo');
const barSpy = spy(ClassB.prototype, 'bar');
const quxSpy = spy(ClassB.prototype, 'qux');
const overriddenSpyA = spy(ClassA.prototype, 'overridden')
const overriddenSpyB = spy(ClassB.prototype, 'overridden')
const b = new ClassB();
expect(fooSpy.called).to.be.true;
expect(barSpy.called).to.be.true;
expect(quxSpy.called).to.be.true;
expect(methods).to.deep.equal(['foo', 'bar', 'qux']);
expect(b.overridden()).to.equal(o + 1);
expect(overriddenSpyA.called).to.be.true;
expect(overriddenSpyB.called).to.be.true;
});
});