jest-vue-matcher
Version:
Additional jest matchers for vue
80 lines (70 loc) • 2.53 kB
Markdown
[](https://www.npmjs.com/package/jest-vue-matcher)
[](https://travis-ci.org/14nrv/jest-vue-matcher)
[](https://codeclimate.com/github/14nrv/jest-vue-matcher/test_coverage)
[](https://codeclimate.com/github/14nrv/jest-vue-matcher/maintainability)
[](https://opensource.org/licenses/MIT)
[](https://github.com/semantic-release/semantic-release)

# jest-vue-matcher
Additional jest matchers for vue
## Install
```
yarn add jest-vue-matcher -D
```
## Setup
```js
import { mount } from '@vue/test-utils'
import matchers from 'jest-vue-matcher'
import MyComponent from '@/components/MyComponent.vue'
let wrapper
describe('MyComponent', () => {
beforeEach(() => {
wrapper = mount(MyComponent)
expect.extend(matchers(wrapper))
})
// ...
})
```
## Matchers available
* toHaveText(text)
```js
expect('h1').toHaveText('My title')
expect('h1').not.toHaveText('Not my title')
```
* toBeADomElement()
```js
expect('h1').toBeADomElement()
expect('notH1').not.toBeADomElement()
```
* toHaveClass(className)
```js
expect('h1').toHaveClass('title')
expect('h1').not.toHaveClass('not-title')
```
* toHaveAttribute(attributeName, attributeValue)
```js
expect('h1').toHaveAttribute('class', 'title')
expect('h1').not.toHaveAClass('class', 'not-title')
```
* toHaveValue(value)
```js
expect('input[type=text]').toHaveValue('plop')
expect('input[type=text]').not.toHaveValue('not plop')
```
* toHaveProp(propName)
```js
expect(wrapper).toHaveProp('propName')
expect(wrapper).not.toHaveProp('not-propName')
```
* toEmit(eventName)
```js
expect(wrapper).toEmit('eventName')
expect(wrapper).not.toEmit('not eventName')
```
* toEmitWith(eventName, eventValue)
```js
expect(wrapper).toEmitWith('eventName', 'eventValue')
expect(wrapper).not.toEmitWith('not eventName', { data: 'eventValue' })
```
## Inspiration
Inspirated by [mwangaben-vthelpers](https://github.com/mwangaben/mwangaben-vthelpers)