-
Notifications
You must be signed in to change notification settings - Fork 5
/
extend.spec.ts
62 lines (50 loc) · 1.17 KB
/
extend.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
import { expect } from 'chai'
import { describe, test } from 'node:test'
import { Context } from '../src'
describe('Extend', () => {
test('basic support', () => {
class S1 {}
class S2 {}
class S3 {}
class C1 extends Context {
s1: S1
s2: S2
s3: S3
}
class C2 extends C1 {}
class C3 extends C1 {}
C2.service('s2', S2)
C1.service('s1', S1)
C3.service('s3', S3)
const c1 = new C1()
expect(c1.s1).to.be.ok
expect(c1.s2).to.be.undefined
expect(c1.s3).to.be.undefined
const c2 = new C2()
expect(c2.s1).to.be.ok
expect(c2.s2).to.be.ok
expect(c2.s3).to.be.undefined
const c3 = new C3()
expect(c3.s1).to.be.ok
expect(c3.s2).to.be.undefined
expect(c3.s3).to.be.ok
})
test('service isolation', () => {
class Temp {}
class C1 extends Context {
temp: Temp
}
class C2 extends C1 {}
C2.service('temp')
const plugin = (ctx: C1) => {
ctx.temp = new Temp()
}
const c1 = new C1()
c1.plugin(plugin)
const c2 = new C2()
c2.plugin(plugin)
// `temp` is not a service of C1
expect(c1.temp).to.be.not.ok
expect(c2.temp).to.be.ok
})
})