Skip to content

Files

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
36 lines (24 loc) · 1.25 KB

setMethods.md

File metadata and controls

36 lines (24 loc) · 1.25 KB

setMethods

::: warning Deprecation warning setMethods is deprecated and will be removed in future releases.

There's no clear path to replace setMethods, because it really depends on your previous usage. It easily leads to flaky tests that rely on implementation details, which is discouraged.

Thus, we suggest to to rethink those tests using the tools Vue Test Utils provides.

If you need to stub out a complex method, extract it out from the component and test it in isolation. On the other hand, if you want to assert that a method is called, use your test runner to spy on it. :::

Sets Wrapper vm methods and forces update on each Wrapper in WrapperArray.

Note every Wrapper must contain a Vue instance.

  • Arguments:

    • {Object} methods
  • Example:

import { mount } from '@vue/test-utils'
import sinon from 'sinon'
import Foo from './Foo.vue'
import Bar from './Bar.vue'

const wrapper = mount(Foo)
const barArray = wrapper.findAll(Bar)
const clickMethodStub = sinon.stub()

barArray.setMethods({ clickMethod: clickMethodStub })
barArray.at(0).trigger('click')
expect(clickMethodStub.called).toBe(true)