You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+65-8
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,14 @@
1
1
# vue-jest
2
2
3
-
Jest Vue transformer with source map support
3
+
Jest transformer for Vue single file components
4
4
5
-
> **NOTE:** This is documentation for `vue-jest@3.x`. [View the vue-jest@2.x documentation](https://github.com/vuejs/vue-jest/tree/e694fc7ce11ae1ac1c778ed7c4402515c5f0d5aa)
5
+
> **NOTE:** This is documentation for `vue-jest@4.x`. [View the vue-jest@3.x documentation](https://github.com/vuejs/vue-jest/tree/v3)
6
6
7
7
## Usage
8
8
9
9
```bash
10
10
npm install --save-dev vue-jest
11
+
yarn add vue-jest --dev
11
12
```
12
13
13
14
### Usage with Babel 7
@@ -16,18 +17,20 @@ If you use [jest](https://github.com/facebook/jest) > 24.0.0 and [babel-jest](ht
16
17
17
18
```bash
18
19
npm install --save-dev babel-core@bridge
20
+
yarn add babel-core@bridge --dev
19
21
```
20
22
21
23
## Setup
22
24
23
-
To define`vue-jest` as a transformer for your `.vue` files, map them to the `vue-jest` module:
25
+
To use`vue-jest` as a transformer for your `.vue` files, map them to the `vue-jest` module:
24
26
25
27
```json
26
28
{
27
29
"jest": {
28
30
"transform": {
29
31
"^.+\\.vue$": "vue-jest"
30
32
}
33
+
}
31
34
}
32
35
```
33
36
@@ -45,18 +48,15 @@ A full config will look like this.
45
48
}
46
49
```
47
50
48
-
If you're on a version of Jest older than 22.4.0, you need to set `mapCoverage` to `true` in order to use source maps.
49
-
50
-
## Example Projects
51
+
## Examples
51
52
52
53
Example repositories testing Vue components with jest and vue-jest:
53
54
54
-
- [Avoriaz with Jest](https://github.com/eddyerburgh/avoriaz-jest-example)
55
55
-[Vue Test Utils with Jest](https://github.com/eddyerburgh/vue-test-utils-jest-example)
56
56
57
57
## Supported langs
58
58
59
-
vue-jest compiles the script and template of SFCs into a JavaScript file that Jest can run. **Currently, SCSS, SASS and Stylus are the only style languages that are compiled**.
59
+
vue-jest compiles `<script />`, `<template />`, and `<style />` blocks with supported `lang` attributes into JavaScript that Jest can run.
60
60
61
61
### Supported script languages
62
62
@@ -67,8 +67,65 @@ vue-jest compiles the script and template of SFCs into a JavaScript file that Je
67
67
68
68
You can change the behavior of `vue-jest` by using `jest.globals`.
69
69
70
+
#### Supporting custom blocks
71
+
72
+
A great feature of the Vue SFC compiler is that it can support custom blocks. You might want to use those blocks in your tests. To render out custom blocks for testing purposes, you'll need to write a transformer. Once you have your transformer, you'll add an entry to vue-jest's transform map. This is how [vue-i18n's](https://github.com/kazupon/vue-i18n)`<i18n>` custom blocks are supported in unit tests.
> _Tip:_ Need programmatic configuration? Use the [--config](https://jestjs.io/docs/en/cli.html#config-path) option in Jest CLI, and export a `.js` file
71
96
97
+
A `jest.config.js` Example - If you're using a dedicated configuration file like you can reference and require your processor in the config file instead of using a file reference.
0 commit comments