Skip to content
On this page

@vue-bridge/testing

current npm versionlicense - MITnpm downloads per month

Installation

You can install this package from NPM. Usually, you would want to add it as a devDependency, for which the commonly used package managers offer the -Dflag:

npm install -D @vue-bridge/testing

yarn add -D @vue-bridge/testing

pnpm add -D @vue-bridge/testing

Peer Dependencies

"peerDependencies": {
    "@vue/test-utils": "^1.2.1 || ^2.0.0-0",
    "vue": "^2.7.0-0 || ^3.2.*"
},

Depending on wether you want to run your test files against Vue 2 or Vue 3, you need to install:

For Vue 2:

  • vue@^2.7 in dependencies
  • @vue/test-utils@^1.2.1 in devDependencies

For Vue 3:

  • vue@^3.2 in dependencies
  • @vue/test-utils@^2.0.0 in devDependencies

Usage

@vue-bridge/testing is meant to be used in place of @vue/test-utils in your tests. It exports most of the shared APIs that both test-utils versions offer, but uses the newer API variants from test utils ^1.0.0. When running in a Vue 2 project, it will convert arguments etc into the older API variants of test-utils ^1.0.

This allows us to write tests in the "new" style, but run them against both the old and new test utils, and by extension, against both major versions of Vue.

import { mount } from '@vue-bridge/testing'

describe('My Test Suit', () => {
  test('My Component mounts with props', () => {
    const wrapper = mount(MyComponent, {
      props: {
        message: 'Hello World',
      }
    })
    expect(wrapper.exists()).toBe(true)
    expect(wrapper.element.innerHTML).toBe('HelloWorld')
  })
})

The above test, when ran in a Vue 2 project, would be run like it was written like this:






 








import { mount } from '@vue-bridge/testing'

describe('My Test Suit', () => {
  test('My Component mounts with props', () => {
    const wrapper = mount(MyComponent, {
      propsData: {
        message: 'Hello World',
      }
    })
    expect(wrapper.exists()).toBe(true)
    expect(wrapper.element.innerHTML).toBe('HelloWorld')
  })
})

API

  • mount()
  • shallowMount()
  • flushPromises()
  • enableAutoUnmount()
  • disableAutoUnmount()
  • isVue2 / isVue3

Released under the MIT license