jest-vue-matcher

Additional jest matchers for vue
15,714 8
Install
npm install jest-vue-matcher
Latest Version:2.0.0
Vue:2
License:MIT
Last Updated:Oct 25, 2020
Links: GitHub  ·  npm
Maintainer: 14nrv

NPM Version Build Status Test Coverage Maintainability License: MIT semantic-release PRs Welcome

jest-vue-matcher

Additional jest matchers for vue

Install

yarn add jest-vue-matcher -D

Setup

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)
    expect('h1').toHaveText('My title')
    expect('h1').not.toHaveText('Not my title')
    
  • toBeADomElement()
    expect('h1').toBeADomElement()
    expect('notH1').not.toBeADomElement()
    
  • toHaveClass(className)
    expect('h1').toHaveClass('title')
    expect('h1').not.toHaveClass('not-title')
    
  • toHaveAttribute(attributeName, attributeValue)
    expect('h1').toHaveAttribute('class', 'title')
    expect('h1').not.toHaveAClass('class', 'not-title')
    
  • toHaveValue(value)
    expect('input[type=text]').toHaveValue('plop')
    expect('input[type=text]').not.toHaveValue('not plop')
    
  • toHaveProp(propName)
    expect(wrapper).toHaveProp('propName')
    expect(wrapper).not.toHaveProp('not-propName')
    
  • toEmit(eventName)
    expect(wrapper).toEmit('eventName')
    expect(wrapper).not.toEmit('not eventName')
    
  • toEmitWith(eventName, eventValue)
    expect(wrapper).toEmitWith('eventName', 'eventValue')
    expect(wrapper).not.toEmitWith('not eventName', { data: 'eventValue' })
    

Inspiration

Inspirated by mwangaben-vthelpers

Related Packages

jest-serializer-vue

A jest serializer for Vue snapshots

15,648,486 63
@forsakringskassan/jest-config-vue

Shareable jest configuration for vue applications

137,449 0
@testforgejs/vue-test-preset-recommended-jest

Official recommended preset for projects using Jest with the TestForge framework

588 0
@testforgejs/vue-test-core

Core testing utilities and pipeline orchestration for the TestForge component te...

622 0
vue-test-utils-compat

Compat layer for @vue/test-utils@2.x

1,187,030

Version History

Version Released License
2.0.0 MIT
1.1.0 MIT
1.0.1 MIT
1.0.0 MIT