An Alternative Vue Test Library

I’ve implemented a test library which aims at a flexible and extendable API. Currently, the feature set is still limited, but already enough to be used in a productive project.

The link to the library is: https://github.com/xiGUAwanOU/easy-vue-test-2

The default example unit test created by vue-cli can be replaced by:

import EasyVueTest, { element, getTextContent } from 'easy-vue-test-2'
import HelloWorld from '@/components/HelloWorld.vue'

describe('HelloWorld.vue', () => {
  it('renders props.msg when passed', async () => {
    const msg = 'new message'
    const easy = await EasyVueTest.mounted(HelloWorld, {
      propsData: { msg }
    })

    expect(easy
      .get(element('h1'))
      .do(getTextContent())
    ).toEqual(msg)
  })
})

You can provide extra accessor methods (like element()) or action methods (like getTextContent()) to extend its ability. Potential use-case can be getElTextInputValue() to get the input value from Element-UI input.

I’m still busying providing the documentation for the library and publish it to npm. Currently, the library can only be installed with git repo reference.

2 Likes