Skip to content

Commit 3c24704

Browse files
committed
test
1 parent 7f99511 commit 3c24704

File tree

16 files changed

+646
-8
lines changed

16 files changed

+646
-8
lines changed

src/component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type ComponentOption = {
5353
provide?: Record<string, any> | Function
5454
components?: Record<string, any>
5555
directives?: Record<string, any>;
56-
inheritAttrs?: boolean;
56+
inheritAttrs?: true;
5757
expose?: string[];
5858
modifier?: (raw: any) => any
5959
}

test/component.ts

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,61 @@ export class Empty extends Base {
88

99
}
1010
const EmptyContext = Empty as any
11+
12+
const FullOptionOpt = {
13+
name: 'FullOption',
14+
emits: ['emits1', 'emits2'],
15+
provide: function () {
16+
return 'provided'
17+
},
18+
components: {
19+
empty: Empty
20+
},
21+
directives: {
22+
directive: {
23+
directiveFlag: {}
24+
}
25+
},
26+
inheritAttrs: true,
27+
expose: ['expose1', 'expose2'],
28+
modifier(option: any) {
29+
option.emits.push('emits3')
30+
return option
31+
}
32+
}
33+
34+
@Component(FullOptionOpt)
35+
export class FullOption extends Base {
36+
37+
}
38+
const FullOptionContext = FullOption as any
1139
describe('Component',
12-
() => describe('Empty', () => {
13-
it('Should be empty', () => {
40+
() => {
41+
it('Empty', () => {
42+
expect('object').to.equal(typeof EmptyContext)
1443
Object.keys(EmptyContext).forEach(key => {
15-
if(key==='data' && typeof EmptyContext[key]==='function'){
44+
if (key === 'data' && typeof EmptyContext[key] === 'function') {
1645
expect(true).to.equal(isEmptyObject(EmptyContext[key]()))
17-
}else{
46+
} else {
1847
expect(true).to.equal(isEmptyObject(EmptyContext[key]))
1948
}
2049
})
2150
})
22-
})
51+
it('Full option', () => {
52+
expect('object').to.equal(typeof FullOptionContext)
53+
Object.keys(FullOptionOpt).forEach(key => {
54+
const opt = (FullOptionOpt as any)[key]
55+
switch (key) {
56+
case 'emits':
57+
expect([...opt, 'emits3'].join(',')).to.equal(FullOptionContext[key].join(','))
58+
break;
59+
case 'modifier':
60+
return;
61+
default:
62+
expect(opt).to.equal(FullOptionContext[key])
63+
}
64+
})
65+
})
66+
}
2367
)
24-
2568
export default {}

test/feature/classExtends.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
import { expect } from 'chai';
3+
import 'mocha';
4+
import { Component, Base } from '../../dist'
5+
class Sup extends Base {
6+
dataSup = 'dataSup value'
7+
data = 'data-sup value'
8+
methodSup() {
9+
return 'methodSup value'
10+
}
11+
method() {
12+
return 'method-sup value'
13+
}
14+
mounted() {
15+
return 'mounted-sup value'
16+
}
17+
}
18+
@Component
19+
export class Comp extends Sup {
20+
dataComp = 'dataComp value'
21+
data = 'data-comp value'
22+
methodComp() {
23+
return 'methodComp value'
24+
}
25+
method() {
26+
return 'method-comp value'
27+
}
28+
mounted() {
29+
return 'mounted-comp value'
30+
}
31+
}
32+
const CompContext = Comp as any
33+
34+
describe('feature class extends',
35+
() => {
36+
it('default', () => {
37+
expect('function').to.equal(typeof CompContext?.methods?.method)
38+
expect('method-comp value').to.equal(CompContext.methods.method())
39+
expect('function').to.equal(typeof CompContext?.methods?.methodComp)
40+
expect('methodComp value').to.equal(CompContext.methods.methodComp())
41+
expect('function').to.equal(typeof CompContext?.methods?.methodSup)
42+
expect('methodSup value').to.equal(CompContext.methods.methodSup())
43+
expect('function').to.equal(typeof CompContext?.data)
44+
const data = CompContext.data()
45+
expect('data-comp value').to.equal(data.data)
46+
expect('dataComp value').to.equal(data.dataComp)
47+
expect('dataSup value').to.equal(data.dataSup)
48+
expect('function').to.equal(typeof CompContext?.mounted)
49+
expect('mounted-comp value').to.equal(CompContext.mounted())
50+
})
51+
}
52+
)
53+
export default {}

test/feature/componentExtends.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
import { expect } from 'chai';
3+
import 'mocha';
4+
import { Component, ComponentBase, Base } from '../../dist'
5+
@ComponentBase
6+
class Sup extends Base {
7+
dataSup = 'dataSup value'
8+
methodSup(){
9+
return 'methodSup value'
10+
}
11+
}
12+
@Component
13+
export class Comp extends Sup {
14+
dataComp = 'dataComp value'
15+
methodComp(){
16+
return 'methodComp value'
17+
}
18+
}
19+
20+
const CompContext = Comp as any
21+
const SupContext = CompContext.extends
22+
describe('feature component extends',
23+
() => {
24+
it('comp', () => {
25+
expect('function').to.equal(typeof CompContext?.data)
26+
const compData = CompContext.data()
27+
expect('dataComp value').to.equal(compData.dataComp)
28+
expect('function').to.equal(typeof CompContext?.methods?.methodComp)
29+
expect('methodComp value').to.equal(CompContext.methods.methodComp())
30+
31+
32+
33+
34+
})
35+
it('sup',()=>{
36+
expect('object').to.equal(typeof SupContext)
37+
expect('function').to.equal(typeof SupContext?.data)
38+
const supData = SupContext.data()
39+
expect('dataSup value').to.equal(supData.dataSup)
40+
expect('function').to.equal(typeof SupContext?.methods?.methodSup)
41+
expect('methodSup value').to.equal(SupContext.methods.methodSup())
42+
})
43+
}
44+
)
45+
export default {}

test/feature/extends.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
2+
import { expect } from 'chai';
3+
import 'mocha';
4+
import { Component, ComponentBase, Base } from '../../dist'
5+
6+
class Comp1Sup extends Base {
7+
method1Sup() {
8+
return 'method1Sup value'
9+
}
10+
}
11+
12+
@ComponentBase
13+
class Comp1 extends Comp1Sup {
14+
method1Comp() {
15+
return 'method1Comp value'
16+
}
17+
}
18+
19+
class Comp2Sup extends Comp1 {
20+
method2Sup() {
21+
return 'method2Sup value'
22+
}
23+
}
24+
25+
@ComponentBase
26+
class Comp2 extends Comp2Sup {
27+
method2Comp() {
28+
return 'method2Comp value'
29+
}
30+
}
31+
32+
class Comp3Sup extends Comp2 {
33+
method3Sup() {
34+
return 'method3Sup value'
35+
}
36+
}
37+
38+
39+
@Component
40+
class Comp3 extends Comp3Sup {
41+
method3Comp() {
42+
return 'method3Comp value'
43+
}
44+
}
45+
46+
const Comp3Context = Comp3 as any
47+
48+
describe('feature extends',
49+
() => {
50+
const Comp2Context = Comp3Context.extends
51+
expect('object').to.equal(typeof Comp2Context)
52+
const Comp1Context = Comp2Context.extends
53+
expect('object').to.equal(typeof Comp1Context)
54+
expect('undefined').to.equal(typeof Comp1Context.extends)
55+
it('comp3', () => {
56+
expect('function').to.equal(typeof Comp3Context?.methods?.method3Comp)
57+
expect('method3Comp value').to.equal(Comp3Context.methods.method3Comp())
58+
expect('function').to.equal(typeof Comp3Context?.methods?.method3Sup)
59+
expect('method3Sup value').to.equal(Comp3Context.methods.method3Sup())
60+
})
61+
it('comp2', () => {
62+
expect('function').to.equal(typeof Comp2Context?.methods?.method2Comp)
63+
expect('method2Comp value').to.equal(Comp2Context.methods.method2Comp())
64+
expect('function').to.equal(typeof Comp2Context?.methods?.method2Sup)
65+
expect('method2Sup value').to.equal(Comp2Context.methods.method2Sup())
66+
})
67+
it('comp1', () => {
68+
expect('function').to.equal(typeof Comp1Context?.methods?.method1Comp)
69+
expect('method1Comp value').to.equal(Comp1Context.methods.method1Comp())
70+
expect('function').to.equal(typeof Comp1Context?.methods?.method1Sup)
71+
expect('method1Sup value').to.equal(Comp1Context.methods.method1Sup())
72+
})
73+
}
74+
)
75+
export default {}

test/feature/lifecycle.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
import { expect } from 'chai';
3+
import 'mocha';
4+
import { Component, Ref, Base } from '../../dist'
5+
6+
@Component
7+
export class Comp extends Base {
8+
mounted(){
9+
return 'mounted test value'
10+
}
11+
12+
}
13+
const CompContext = Comp as any
14+
15+
describe('feature lifecycle',
16+
() => {
17+
it('default', () => {
18+
expect('undefined').to.equal(typeof CompContext?.methods?.mounted)
19+
expect('function').to.equal(typeof CompContext?.mounted)
20+
expect('mounted test value').to.equal(CompContext?.mounted())
21+
})
22+
}
23+
)
24+
export default {}

test/internal/utils.ts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
2+
import { expect } from 'chai';
3+
import 'mocha';
4+
import { Base } from '../../dist'
5+
import * as Utils from '../../dist/utils'
6+
7+
8+
class Comp1Sup extends Base {
9+
method1Sup() {
10+
return 'method1Sup value'
11+
}
12+
}
13+
14+
15+
class Comp1 extends Comp1Sup {
16+
method1Comp() {
17+
return 'method1Comp value'
18+
}
19+
}
20+
21+
class Comp2Sup extends Comp1 {
22+
method2Sup() {
23+
return 'method2Sup value'
24+
}
25+
}
26+
27+
28+
class Comp2 extends Comp2Sup {
29+
method2Comp() {
30+
return 'method2Comp value'
31+
}
32+
}
33+
34+
class Comp3Sup extends Comp2 {
35+
method3Sup() {
36+
return 'method3Sup value'
37+
}
38+
}
39+
40+
41+
42+
class Comp3 extends Comp3Sup {
43+
method3Comp() {
44+
return 'method3Comp value'
45+
}
46+
}
47+
48+
describe('internal utils',
49+
() => {
50+
it('slot', () => {
51+
expect(true).to.equal(Utils.obtainSlot(Comp3.prototype).names instanceof Map)
52+
})
53+
it('toComponentReverse', () => {
54+
Utils.obtainSlot(Comp2.prototype)
55+
Utils.obtainSlot(Comp1.prototype)
56+
57+
const path3 = Utils.toComponentReverse(Comp3.prototype)
58+
59+
expect(2).to.equal(path3.length)
60+
61+
expect(Comp3Sup).to.equal(path3[0].constructor)
62+
expect(true).to.equal(path3[0] instanceof Comp2)
63+
64+
expect(Comp3).to.equal(path3[1].constructor)
65+
expect(true).to.equal(path3[1] instanceof Comp3Sup)
66+
67+
const path2 = Utils.toComponentReverse(Comp2.prototype)
68+
expect(2).to.equal(path2.length)
69+
70+
expect(Comp2Sup).to.equal(path2[0].constructor)
71+
expect(true).to.equal(path2[0] instanceof Comp1)
72+
73+
expect(Comp2).to.equal(path2[1].constructor)
74+
expect(true).to.equal(path2[1] instanceof Comp2Sup)
75+
76+
const path1 = Utils.toComponentReverse(Comp1.prototype)
77+
expect(2).to.equal(path1.length)
78+
79+
expect(Comp1Sup).to.equal(path1[0].constructor)
80+
expect(true).to.equal(path1[0] instanceof Base)
81+
82+
expect(Comp1).to.equal(path1[1].constructor)
83+
expect(true).to.equal(path1[1] instanceof Comp1Sup)
84+
})
85+
86+
it('extendSlotPath', () => {
87+
const path = Utils.extendSlotPath(Comp3.prototype)
88+
expect(3).to.equal(path.length)
89+
expect(Comp3.prototype).to.equal(path[0])
90+
expect(Comp2.prototype).to.equal(path[1])
91+
expect(Comp1.prototype).to.equal(path[2])
92+
})
93+
}
94+
)
95+
export default {}

0 commit comments

Comments
 (0)