Skip to content

Commit 54f4cc1

Browse files
author
鲍勇翔
committed
add unit test : v-stream directive (with .native modify)
1 parent ddee876 commit 54f4cc1

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ require('rxjs/add/operator/map')
1717
require('rxjs/add/operator/startWith')
1818
require('rxjs/add/operator/scan')
1919
require('rxjs/add/operator/pluck')
20+
require('rxjs/add/operator/merge')
2021

2122
const miniRx = {
2223
Observable,
@@ -141,6 +142,39 @@ test('v-stream directive (basic)', done => {
141142
})
142143
})
143144

145+
test('v-stream directive (with .native modify)', done => {
146+
const vm = new Vue({
147+
template: `
148+
<div>
149+
<span class="count">{{ count }}</span>
150+
<my-button v-stream:click.native="clickNative$">+</my-button>
151+
<my-button v-stream:click="click$">-</my-button>
152+
</div>
153+
`,
154+
components: {
155+
myButton: {
156+
template: '<button>MyButton</button>'
157+
}
158+
},
159+
domStreams: ['clickNative$', 'click$'],
160+
subscriptions () {
161+
return {
162+
count: this.click$.map(() => -1)
163+
.merge(this.clickNative$.map(() => 1))
164+
.startWith(0)
165+
.scan((total, change) => total + change)
166+
}
167+
}
168+
}).$mount()
169+
170+
expect(vm.$el.querySelector('span').textContent).toBe('0')
171+
click(vm.$el.querySelector('button'))
172+
nextTick(() => {
173+
expect(vm.$el.querySelector('span').textContent).toBe('1')
174+
done()
175+
})
176+
})
177+
144178
test('v-stream directive (with data)', done => {
145179
const vm = new Vue({
146180
data: {

0 commit comments

Comments
 (0)