Skip to content

Trigger disregards setMethods and remains referencing the old one #615

Closed
@lchanmann

Description

@lchanmann

Version

1.0.0-beta.16

Reproduction link

https://github.com/lchanmann/vue-test-utils-setMethods-issue

Steps to reproduce

Clone the repo, then run:

yarn install
yarn test

What is expected?

Should pass tests

What is actually happening?

Test fails

FAIL  ./setMethods.test.js
 ● Console

   console.log setMethods.test.js:9
     clickMethod

 ● setMethods › calls stub when event is triggered

   expect(jest.fn()).toHaveBeenCalled()

   Expected mock function to have been called.

     at Object.<anonymous> (setMethods.test.js:17:29)
         at new Promise (<anonymous>)
         at <anonymous>
     at process._tickCallback (internal/process/next_tick.js:188:7)

setMethods.test.js

import { mount } from '@vue/test-utils'

describe('setMethods', () => {
  it('calls stub when event is triggered', () => {
    const TestComponent = {
      template: '<button @click="clickMethod">Click here</button>',
      methods: {
        clickMethod() {
          console.log('clickMethod')
        }
      }
    }
    const wrapper = mount(TestComponent)
    const clickMethodStub = jest.fn()
    wrapper.setMethods({ clickMethod: clickMethodStub })
    wrapper.find('button').trigger('click')
    expect(clickMethodStub).toHaveBeenCalled()
  })
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions