Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add unit test : v-stream directive (with .native modify)
  • Loading branch information
鲍勇翔 committed Aug 26, 2017
commit 54f4cc1c15e1a2d2e58e7cea6aebce1bef99958c
34 changes: 34 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require('rxjs/add/operator/map')
require('rxjs/add/operator/startWith')
require('rxjs/add/operator/scan')
require('rxjs/add/operator/pluck')
require('rxjs/add/operator/merge')

const miniRx = {
Observable,
Expand Down Expand Up @@ -141,6 +142,39 @@ test('v-stream directive (basic)', done => {
})
})

test('v-stream directive (with .native modify)', done => {
const vm = new Vue({
template: `
<div>
<span class="count">{{ count }}</span>
<my-button v-stream:click.native="clickNative$">+</my-button>
<my-button v-stream:click="click$">-</my-button>
</div>
`,
components: {
myButton: {
template: '<button>MyButton</button>'
}
},
domStreams: ['clickNative$', 'click$'],
subscriptions () {
return {
count: this.click$.map(() => -1)
.merge(this.clickNative$.map(() => 1))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This map operator function should asserting the passing argument is indeed a native event

.startWith(0)
.scan((total, change) => total + change)
}
}
}).$mount()

expect(vm.$el.querySelector('span').textContent).toBe('0')
click(vm.$el.querySelector('button'))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two buttons, use ID selector

nextTick(() => {
expect(vm.$el.querySelector('span').textContent).toBe('1')
done()
})
})

test('v-stream directive (with data)', done => {
const vm = new Vue({
data: {
Expand Down