-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
715 additions
and
316 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<script setup lang="ts"> | ||
import { DemoService } from './DemoService'; | ||
import { OtherService } from './OtherService'; | ||
import { declareProviders, useService } from '../../src/index'; | ||
defineProps({ | ||
msg: String, | ||
}); | ||
declareProviders(con => { | ||
con.bind(DemoService).to(DemoService); | ||
con.bind(OtherService).to(OtherService); | ||
}); | ||
const service = useService(DemoService); | ||
defineExpose({ | ||
service, | ||
}); | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<div class="msg">{{ msg }}</div> | ||
<div class="count">{{ service.count }}</div> | ||
<div class="other-count">{{ service.otherService.count }}</div> | ||
<div class="age">{{ service.age }}</div> | ||
<div class="name">{{ service.name }}</div> | ||
<div class="computedName">{{ service.computedName }}</div> | ||
|
||
<button type="button" class="btn-age" @click="service.increaseAge()"> | ||
Add age | ||
</button> | ||
<button type="button" class="btn-count" @click="service.increaseCount()"> | ||
Add count | ||
</button> | ||
<button | ||
type="button" | ||
class="btn-other-count" | ||
@click="service.increaseOtherCount()" | ||
> | ||
Add other count | ||
</button> | ||
</div> | ||
</template> |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<script setup lang="ts"> | ||
import { DemoService } from './DemoService'; | ||
import { OtherService } from './OtherService'; | ||
import { declareProviders, useService } from '../../src/index'; | ||
defineProps({ | ||
msg: String, | ||
}); | ||
declareProviders(con => { | ||
con.bind(DemoService).toSelf(); | ||
con.bind(OtherService).toSelf(); | ||
}); | ||
const service = useService(DemoService); | ||
defineExpose({ | ||
service, | ||
}); | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<div class="msg">{{ msg }}</div> | ||
<div class="count">{{ service.count }}</div> | ||
<div class="other-count">{{ service.otherService.count }}</div> | ||
<div class="age">{{ service.age }}</div> | ||
<div class="name">{{ service.name }}</div> | ||
<div class="computedName">{{ service.computedName }}</div> | ||
|
||
<button type="button" class="btn-age" @click="service.increaseAge()"> | ||
Add age | ||
</button> | ||
<button type="button" class="btn-count" @click="service.increaseCount()"> | ||
Add count | ||
</button> | ||
<button | ||
type="button" | ||
class="btn-other-count" | ||
@click="service.increaseOtherCount()" | ||
> | ||
Add other count | ||
</button> | ||
</div> | ||
</template> |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { computed } from 'vue'; | ||
import { postReactive } from '../../src/index'; | ||
import { inject } from 'inversify'; | ||
import { OtherService } from './OtherService'; | ||
|
||
export class DemoService { | ||
public count = 1; | ||
public age = 100; | ||
private _name = 'DemoService'; | ||
public computedName: any; | ||
|
||
@inject(OtherService) | ||
public otherService!: OtherService; | ||
|
||
public increaseOtherCount() { | ||
this.otherService.increaseCount(); | ||
} | ||
|
||
public increaseCount() { | ||
this.count++; | ||
} | ||
|
||
public increaseAge() { | ||
this.age++; | ||
} | ||
|
||
public get name() { | ||
return `${this._name}-${this.age}`; | ||
} | ||
|
||
@postReactive() | ||
public init() { | ||
this.computedName = computed(() => { | ||
return `${this._name}-${this.age}`; | ||
}); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class OtherService { | ||
public count = 100; | ||
|
||
public increaseCount() { | ||
this.count += 10; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 测试场景-验证to方法和toSelf方法 | ||
|
||
验证to方法和toSelf方法 |
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 |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import 'reflect-metadata'; | ||
import { mount } from '@vue/test-utils'; | ||
import DemoCompTo from './DemoCompTo.vue'; | ||
import DemoCompToSelf from './DemoCompToSelf.vue'; | ||
import { DemoService } from './DemoService'; | ||
import { OtherService } from './OtherService'; | ||
|
||
describe('test6', () => { | ||
it('DemoCompTo.vue use bind to', async () => { | ||
const msg = 'Hello world'; | ||
const wrapper = mount(DemoCompTo, { | ||
props: { | ||
msg, | ||
}, | ||
}); | ||
|
||
expect(wrapper.vm.service).toBeInstanceOf(DemoService); | ||
expect(wrapper.vm.service.otherService).toBeInstanceOf(OtherService); | ||
|
||
expect(wrapper.get('.msg').text()).toBe(msg); | ||
expect(wrapper.get('.count').text()).toBe('1'); | ||
expect(wrapper.get('.other-count').text()).toBe('100'); | ||
expect(wrapper.get('.age').text()).toBe('100'); | ||
expect(wrapper.get('.name').text()).toBe('DemoService-100'); | ||
expect(wrapper.get('.computedName').text()).toBe('DemoService-100'); | ||
|
||
await wrapper.get('.btn-count').trigger('click'); | ||
expect(wrapper.get('.msg').text()).toBe(msg); | ||
expect(wrapper.get('.count').text()).toBe('2'); | ||
expect(wrapper.get('.other-count').text()).toBe('100'); | ||
expect(wrapper.get('.age').text()).toBe('100'); | ||
expect(wrapper.get('.name').text()).toBe('DemoService-100'); | ||
expect(wrapper.get('.computedName').text()).toBe('DemoService-100'); | ||
|
||
await wrapper.get('.btn-count').trigger('click'); | ||
expect(wrapper.get('.msg').text()).toBe(msg); | ||
expect(wrapper.get('.count').text()).toBe('3'); | ||
expect(wrapper.get('.other-count').text()).toBe('100'); | ||
expect(wrapper.get('.age').text()).toBe('100'); | ||
expect(wrapper.get('.name').text()).toBe('DemoService-100'); | ||
expect(wrapper.get('.computedName').text()).toBe('DemoService-100'); | ||
|
||
await wrapper.get('.btn-other-count').trigger('click'); | ||
expect(wrapper.get('.msg').text()).toBe(msg); | ||
expect(wrapper.get('.count').text()).toBe('3'); | ||
expect(wrapper.get('.other-count').text()).toBe('110'); | ||
expect(wrapper.get('.age').text()).toBe('100'); | ||
expect(wrapper.get('.name').text()).toBe('DemoService-100'); | ||
expect(wrapper.get('.computedName').text()).toBe('DemoService-100'); | ||
|
||
await wrapper.get('.btn-age').trigger('click'); | ||
expect(wrapper.get('.msg').text()).toBe(msg); | ||
expect(wrapper.get('.count').text()).toBe('3'); | ||
expect(wrapper.get('.other-count').text()).toBe('110'); | ||
expect(wrapper.get('.age').text()).toBe('101'); | ||
expect(wrapper.get('.name').text()).toBe('DemoService-101'); | ||
expect(wrapper.get('.computedName').text()).toBe('DemoService-101'); | ||
|
||
await wrapper.get('.btn-age').trigger('click'); | ||
expect(wrapper.get('.msg').text()).toBe(msg); | ||
expect(wrapper.get('.count').text()).toBe('3'); | ||
expect(wrapper.get('.other-count').text()).toBe('110'); | ||
expect(wrapper.get('.age').text()).toBe('102'); | ||
expect(wrapper.get('.name').text()).toBe('DemoService-102'); | ||
expect(wrapper.get('.computedName').text()).toBe('DemoService-102'); | ||
}); | ||
|
||
it('DemoCompToSelf.vue use bind toSelf', async () => { | ||
const msg = 'Hello world'; | ||
const wrapper = mount(DemoCompToSelf, { | ||
props: { | ||
msg, | ||
}, | ||
}); | ||
|
||
expect(wrapper.vm.service).toBeInstanceOf(DemoService); | ||
expect(wrapper.vm.service.otherService).toBeInstanceOf(OtherService); | ||
|
||
expect(wrapper.get('.msg').text()).toBe(msg); | ||
expect(wrapper.get('.count').text()).toBe('1'); | ||
expect(wrapper.get('.other-count').text()).toBe('100'); | ||
expect(wrapper.get('.age').text()).toBe('100'); | ||
expect(wrapper.get('.name').text()).toBe('DemoService-100'); | ||
expect(wrapper.get('.computedName').text()).toBe('DemoService-100'); | ||
|
||
await wrapper.get('.btn-count').trigger('click'); | ||
expect(wrapper.get('.msg').text()).toBe(msg); | ||
expect(wrapper.get('.count').text()).toBe('2'); | ||
expect(wrapper.get('.other-count').text()).toBe('100'); | ||
expect(wrapper.get('.age').text()).toBe('100'); | ||
expect(wrapper.get('.name').text()).toBe('DemoService-100'); | ||
expect(wrapper.get('.computedName').text()).toBe('DemoService-100'); | ||
|
||
await wrapper.get('.btn-count').trigger('click'); | ||
expect(wrapper.get('.msg').text()).toBe(msg); | ||
expect(wrapper.get('.count').text()).toBe('3'); | ||
expect(wrapper.get('.other-count').text()).toBe('100'); | ||
expect(wrapper.get('.age').text()).toBe('100'); | ||
expect(wrapper.get('.name').text()).toBe('DemoService-100'); | ||
expect(wrapper.get('.computedName').text()).toBe('DemoService-100'); | ||
|
||
await wrapper.get('.btn-other-count').trigger('click'); | ||
expect(wrapper.get('.msg').text()).toBe(msg); | ||
expect(wrapper.get('.count').text()).toBe('3'); | ||
expect(wrapper.get('.other-count').text()).toBe('110'); | ||
expect(wrapper.get('.age').text()).toBe('100'); | ||
expect(wrapper.get('.name').text()).toBe('DemoService-100'); | ||
expect(wrapper.get('.computedName').text()).toBe('DemoService-100'); | ||
|
||
await wrapper.get('.btn-age').trigger('click'); | ||
expect(wrapper.get('.msg').text()).toBe(msg); | ||
expect(wrapper.get('.count').text()).toBe('3'); | ||
expect(wrapper.get('.other-count').text()).toBe('110'); | ||
expect(wrapper.get('.age').text()).toBe('101'); | ||
expect(wrapper.get('.name').text()).toBe('DemoService-101'); | ||
expect(wrapper.get('.computedName').text()).toBe('DemoService-101'); | ||
|
||
await wrapper.get('.btn-age').trigger('click'); | ||
expect(wrapper.get('.msg').text()).toBe(msg); | ||
expect(wrapper.get('.count').text()).toBe('3'); | ||
expect(wrapper.get('.other-count').text()).toBe('110'); | ||
expect(wrapper.get('.age').text()).toBe('102'); | ||
expect(wrapper.get('.name').text()).toBe('DemoService-102'); | ||
expect(wrapper.get('.computedName').text()).toBe('DemoService-102'); | ||
}); | ||
}); |
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