Skip to content

Commit c28b566

Browse files
committed
tests for functional component api improvements
1 parent d2b7142 commit c28b566

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

test/unit/features/options/functional.spec.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,53 @@ describe('Options functional', () => {
2222
}).then(done)
2323
})
2424

25+
it('should expose all props when not declared', done => {
26+
const vm = new Vue({
27+
data: { test: 'foo' },
28+
template: '<div><wrap :msg="test" kebab-msg="bar"></wrap></div>',
29+
components: {
30+
wrap: {
31+
functional: true,
32+
render (h, { props }) {
33+
return h('div', `${props.msg} ${props.kebabMsg}`)
34+
}
35+
}
36+
}
37+
}).$mount()
38+
expect(vm.$el.innerHTML).toBe('<div>foo bar</div>')
39+
vm.test = 'qux'
40+
waitForUpdate(() => {
41+
expect(vm.$el.innerHTML).toBe('<div>qux bar</div>')
42+
}).then(done)
43+
})
44+
45+
it('should expose data.on as listeners', () => {
46+
const foo = jasmine.createSpy('foo')
47+
const bar = jasmine.createSpy('bar')
48+
const vm = new Vue({
49+
template: '<div><wrap @click="foo" @test="bar"/></div>',
50+
methods: { foo, bar },
51+
components: {
52+
wrap: {
53+
functional: true,
54+
render (h, { listeners }) {
55+
return h('div', {
56+
on: {
57+
click: [listeners.click, () => listeners.test('bar')]
58+
}
59+
})
60+
}
61+
}
62+
}
63+
}).$mount()
64+
65+
triggerEvent(vm.$el.children[0], 'click')
66+
expect(foo).toHaveBeenCalled()
67+
expect(foo.calls.argsFor(0)[0].type).toBe('click') // should have click event
68+
triggerEvent(vm.$el.children[0], 'mousedown')
69+
expect(bar).toHaveBeenCalledWith('bar')
70+
})
71+
2572
it('should support returning more than one root node', () => {
2673
const vm = new Vue({
2774
template: `<div><test></test></div>`,

0 commit comments

Comments
 (0)