Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Add installation for each vue/jest version combination #388

Merged
merged 4 commits into from
Sep 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 26 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
# vue-jest

Jest transformer for Vue single file components
Jest transformer for Vue Single File Components.

> **NOTE:** This is documentation for `[email protected]`. [View the [email protected] documentation](https://github.com/vuejs/vue-jest/tree/v3)
## Installation

## Usage
Since we need to support a variety of Vue and Jest versions, vue-jest doesn't follow semantic versioning.

```bash
npm install --save-dev vue-jest
yarn add vue-jest --dev
```

### Usage with Babel 7

If you use [jest](https://github.com/facebook/jest) > 24.0.0 and [babel-jest](https://github.com/facebook/jest/tree/master/packages/babel-jest) make sure to install babel-core@bridge
| Vue version | Jest Version | Package |
| ----------- | ----------------- | ------------------- |
| Vue 2 | Jest 26 and below | `vue-jest@4` |
| Vue 3 | Jest 26 and below | `vue-jest@5` |
| Vue 2 | Jest 27 | `@vue/vue2-jest@27` |
| Vue 3 | Jest 27 | `@vue/vue3-jest@27` |

```bash
npm install --save-dev babel-core@bridge
yarn add babel-core@bridge --dev
npm install --save-dev @vue/vue2-jest@27 # (use the appropriate version)
yarn add @vue/vue2-jest@27 --dev
```

## Setup

To use `vue-jest` as a transformer for your `.vue` files, map them to the `vue-jest` module:
To use `vue-jest` as a transformer for your `.vue` files, map them to the appropriate `vue-jest` module:

```json
{
"jest": {
"transform": {
"^.+\\.vue$": "vue-jest"
"^.+\\.vue$": "@vue/vue2-jest" // Update to match your installed version
}
}
}
Expand All @@ -42,19 +40,22 @@ A full config will look like this.
"moduleFileExtensions": ["js", "json", "vue"],
"transform": {
"^.+\\.js$": "babel-jest",
"^.+\\.vue$": "vue-jest"
"^.+\\.vue$": "@vue/vue2-jest"
}
}
}
```

## Examples
### Usage with Babel 7
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't write this one, simply reordered it


Example repositories testing Vue components with jest and vue-jest:
If you use [jest](https://github.com/facebook/jest) > 24.0.0 and [babel-jest](https://github.com/facebook/jest/tree/master/packages/babel-jest) make sure to install babel-core@bridge

- [Vue Test Utils with Jest](https://github.com/eddyerburgh/vue-test-utils-jest-example)
```bash
npm install --save-dev babel-core@bridge
yarn add babel-core@bridge --dev
```

## Supported langs
## Supported languages for SFC sections

vue-jest compiles `<script />`, `<template />`, and `<style />` blocks with supported `lang` attributes into JavaScript that Jest can run.

Expand All @@ -79,10 +80,10 @@ A `package.json` Example
"moduleFileExtensions": ["js", "json", "vue"],
"transform": {
"^.+\\.js$": "babel-jest",
"^.+\\.vue$": "vue-jest"
"^.+\\.vue$": "@vue/vue2-jest"
},
"globals": {
"vue-jest": {
"@vue/vue2-jest": {
"transform": {
"your-custom-block": "./custom-block-processor.js"
}
Expand All @@ -99,7 +100,7 @@ A `jest.config.js` Example - If you're using a dedicated configuration file like
```js
module.exports = {
globals: {
'vue-jest': {
'@vue/vue2-jest': {
transform: {
'your-custom-block': require('./custom-block-processor')
}
Expand Down Expand Up @@ -134,7 +135,7 @@ You can provide [TemplateCompileOptions](https://github.com/vuejs/component-comp
{
"jest": {
"globals": {
"vue-jest": {
"@vue/vue2-jest": {
"templateCompiler": {
"transpileOptions": {
"transforms": {
Expand All @@ -159,7 +160,7 @@ You can provide [TemplateCompileOptions](https://github.com/vuejs/component-comp
{
"jest": {
"globals": {
"vue-jest": {
"@vue/vue2-jest": {
"pug": {
"basedir": "mybasedir"
}
Expand Down