Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/locoslab/vue-jest-utils
Utilities for testing Vue.js components using Jest
https://github.com/locoslab/vue-jest-utils
Last synced: 26 days ago
JSON representation
Utilities for testing Vue.js components using Jest
- Host: GitHub
- URL: https://github.com/locoslab/vue-jest-utils
- Owner: locoslab
- License: mit
- Archived: true
- Created: 2016-10-05T17:02:55.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-20T15:35:47.000Z (about 6 years ago)
- Last Synced: 2024-01-03T23:39:42.185Z (5 months ago)
- Language: TypeScript
- Size: 11.7 KB
- Stars: 47
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-vue - vue-jest-utils - Utilities for testing Vue.js components using Jest. (Components & Libraries / Integrations)
- awesome-vue - vue-jest-utils - Utilities for testing Vue.js components using Jest. (Components & Libraries / Integrations)
- awesome-vue - vue-jest-utils - Utilities for testing Vue.js components using Jest. (Components & Libraries / Integrations)
- awesome-vue - vue-jest-utils - Utilities for testing Vue.js components using Jest. (Components & Libraries / Integrations)
- awesome-vue - vue-jest-utils - Utilities for testing Vue.js components using Jest. (Components & Libraries / Integrations)
- awesome-vue-refactor - vue-jest-utils
- awesomer-vue - vue-jest-utils - Utilities for testing Vue.js components using Jest. (Integrations / Miscellaneous)
- awesome-vue - vue-jest-utils - Utilities for testing Vue.js components using Jest. (Components & Libraries / Integrations)
- awesome-vue - vue-jest-utils - Utilities for testing Vue.js components using Jest. (Components & Libraries / Integrations)
- awesome-vue - vue-jest-utils - Utilities for testing Vue.js components using Jest. (Components & Libraries / Integrations)
- awesome-vue - vue-jest-utils - Utilities for testing Vue.js components using Jest. (Components & Libraries / Integrations)
- awesome-vue - vue-jest-utils - Utilities for testing Vue.js components using Jest. (Integrations / Payment)
- awesome-vue - vue-jest-utils - Utilities for testing Vue.js components using Jest. (Integrations / Payment)
- awesome-vue - vue-jest-utils - Utilities for testing Vue.js components using Jest. (Integrations / Payment)
- awesome-vue - vue-jest-utils - Utilities for testing Vue.js components using Jest. (Integrations / Payment)
- awesome-vue. - vue-jest-utils - Utilities for testing Vue.js components using Jest. (Integrations / Payment)
- awesome-vue - vue-jest-utils - Utilities for testing Vue.js components using Jest. (Integrations / Payment)
- awesome-vue - vue-jest-utils ★44 - Utilities for testing Vue.js components using Jest. (Integrations / Payment)
- awesome-vue - vue-jest-utils - Utilities for testing Vue.js components using Jest. (Components & Libraries / Integrations)
- awesome-vuejs - vue-jest-utils - Utilities for testing Vue.js components using Jest. (Integrations / Web Sockets)
README
# vue-jest-utils [![Build Status](https://travis-ci.org/locoslab/vue-jest-utils.svg?branch=master)](https://travis-ci.org/locoslab/vue-jest-utils) [![npm version](https://badge.fury.io/js/vue-jest-utils.svg)](https://badge.fury.io/js/vue-jest-utils)
Utilities for testing [Vue.js](http://vuejs.org/) components using [Jest](https://facebook.github.io/jest/).While written in TypeScript (and thus including type definitions), it can also be used in a pure JavaScript environment.
Disclaimer: this project is currently very much work-in-progress. The motivating use case is simplifying snapshot testing using a combination of Vue.js, TypeScript, Jest, and html2jade. Additional functionality will be added as needed and breaking API changes may happen before releasing 1.0. Contributions are more than welcome.
## Usage
Install: `npm install --save-dev vue-jest-utils`Note: Vue.js 2.0 and Jest must be installed as well.
To use Jest with Vue.js single-file components (`*.vue`) or TypeScript sources, follow the guide on [vue-typescript-jest](https://github.com/locoslab/vue-typescript-jest).
For a complete example of a TypeScript/Tsify/Vue.js/Vueify/Pug setup supporting Hot Module Replacement and unit/snapshot testing with Jest, cf. [vue-typescript-component-example](https://github.com/locoslab/vue-typescript-component-example).
### Examples
#### JavaScript Test Example
```javascript
const Vue = require('vue')
const VJU = require('vue-jest-utils')const CounterJs = require('../src/counter-js.vue')
describe('counter-js.vue', () => {
it('should just work', () => {
const vm = new Vue({
el: document.createElement('div'),
render: (h) => h(CounterJs),
})
VJU.clickNthButton(vm.$el, 1)
VJU.clickNthButton(vm.$el, 3)
VJU.clickNthButton(vm.$el, 2)
// return a Promise that
// 1. calls vm.nextTick()
// 2. checks the snapshot of vm.$el using html2jade
return VJU.expectToMatchSnapshot(vm)
})
})
```#### TypeScript Test Example
```typescript
///import Vue = require('vue')
import {expectToMatchSnapshot, clickNthButton} from 'vue-jest-utils'
import CounterTs = require('../src/counter-ts.vue')describe('counter-ts.vue', () => {
it('should just work', () => {
const vm = new Vue({
el: document.createElement('div'),
render: (h) => h(CounterTs),
})
clickNthButton(vm.$el, 1)
clickNthButton(vm.$el, 3)
clickNthButton(vm.$el, 2)
// return a Promise that
// 1. calls vm.nextTick()
// 2. checks the snapshot of vm.$el using html2jade
return expectToMatchSnapshot(vm)
})
})
```## Contributing
Contributions including bug reports, tests, and documentation are more than welcome. To get started with development:
``` bash
# once: install dependencies
npm install# run unit tests in watch mode
npm test -- --watch# lint & test
npm run prepublish
```## License
[MIT](http://opensource.org/licenses/MIT)