Skip to content

Commit 2d445be

Browse files
committed
Added usage section to readme
1 parent 769c0d5 commit 2d445be

File tree

2 files changed

+4003
-0
lines changed

2 files changed

+4003
-0
lines changed

README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,87 @@ It's primary guiding principle is:
2222

2323
The more your tests resemble the way your software is used, the more confidence they can give you.
2424

25+
## Installation
26+
27+
This module is distributed via [npm][npm] which is bundled with [node][node] and
28+
should be installed as one of your project's `devDependencies`:
29+
30+
```
31+
npm install --save-dev vue-testing-library
32+
33+
```
34+
35+
## Usage
36+
37+
```
38+
npm install --save-dev vue-testing-library
39+
jest
40+
vue-jest
41+
babel-jest
42+
babel-preset-env
43+
babel-plugin-transform-runtime
44+
```
45+
46+
```javascript
47+
// package.json
48+
"scripts": {
49+
"test": "jest"
50+
}
51+
52+
"jest": {
53+
"moduleDirectories": [
54+
"node_modules",
55+
"src"
56+
],
57+
"moduleFileExtensions": [
58+
"js",
59+
"vue"
60+
],
61+
"testPathIgnorePatterns": [
62+
"/node_modules/"
63+
],
64+
"transform": {
65+
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
66+
".*\\.(vue)$": "<rootDir>/node_modules/vue-jest"
67+
}
68+
}
69+
70+
// .babelrc
71+
{
72+
"presets": [
73+
["env", {
74+
"modules": false,
75+
"targets": {
76+
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
77+
}
78+
}]
79+
],
80+
"plugins": [
81+
"transform-runtime"
82+
],
83+
"env": {
84+
"test": {
85+
"presets": ["env"]
86+
}
87+
}
88+
}
89+
90+
// src/TestComponent.vue
91+
<template>
92+
<span data-testid="test1">Hello World</span>
93+
</template>
94+
95+
// src/TestComponent.spec.js
96+
import { render } from 'vue-testing-library'
97+
import TestComponent from './TestComponent'
98+
99+
test('should render HelloWorld', () => {
100+
const { queryByTestId } = render(TestComponent)
101+
expect(queryByTestId('test1').textContent).toBe('Hello World')
102+
})
103+
104+
```
105+
25106
## LICENSE
26107

27108
MIT

0 commit comments

Comments
 (0)