test: test case for #3300, #3301

This commit is contained in:
Evan You 2021-02-25 09:07:49 -05:00
parent e3568bae27
commit 75964aba03

View File

@ -78,6 +78,8 @@ describe('api: options', () => {
test('methods', async () => { test('methods', async () => {
const Comp = defineComponent({ const Comp = defineComponent({
data() { data() {
// #3300 method on ctx should be overwritable
this.incBy = this.incBy.bind(this, 2)
return { return {
foo: 1 foo: 1
} }
@ -85,13 +87,17 @@ describe('api: options', () => {
methods: { methods: {
inc() { inc() {
this.foo++ this.foo++
},
incBy(n = 0) {
this.foo += n
} }
}, },
render() { render() {
return h( return h(
'div', 'div',
{ {
onClick: this.inc onClick: this.inc,
onFoo: this.incBy
}, },
this.foo this.foo
) )
@ -104,6 +110,10 @@ describe('api: options', () => {
triggerEvent(root.children[0] as TestElement, 'click') triggerEvent(root.children[0] as TestElement, 'click')
await nextTick() await nextTick()
expect(serializeInner(root)).toBe(`<div>2</div>`) expect(serializeInner(root)).toBe(`<div>2</div>`)
triggerEvent(root.children[0] as TestElement, 'foo')
await nextTick()
expect(serializeInner(root)).toBe(`<div>4</div>`)
}) })
test('components own methods have higher priority than global properties', async () => { test('components own methods have higher priority than global properties', async () => {