Skip to content

Commit d349f6b

Browse files
Update jest.md
1 parent f2f7307 commit d349f6b

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

recipes/javascript/tests/jest.md

+31-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ Use the following pattern for placing naming your test scripts, so Jest can find
1010

1111

1212

13-
## Sample
13+
## Samples
14+
15+
### Plain JavaScript
1416

1517
Install with:
1618

@@ -46,6 +48,13 @@ $ npm install jest -D
4648
test('Square a number successfully', () => {
4749
expect(foo(3)).toBe(9)
4850
})
51+
52+
// To group cases, use `describe` and `it` (which is an alias for `test`).
53+
describe("Hello.vue", () => {
54+
it("can square a number successfully", () => {
55+
expect(foo(3)).toEqual(9);
56+
});
57+
});
4958
```
5059

5160
Then run as:
@@ -59,3 +68,24 @@ You can also generate a Jest config:
5968
```sh
6069
$ jest --init
6170
```
71+
72+
### Vue
73+
74+
Based on the file generated when adding the [Vue Jest plugin](https://cli.vuejs.org/core-plugins/unit-jest.html).
75+
76+
- `Helloworld.spec.js`
77+
```vue
78+
import Help from "@/components/Hello.vue";
79+
import { shallowMount } from "@vue/test-utils";
80+
81+
describe("Hello.vue", () => {
82+
it("renders props.message when passed", () => {
83+
const message = "Hello, world!";
84+
const wrapper = shallowMount(Hello, {
85+
propsData: { message },
86+
});
87+
88+
expect(wrapper.text()).toMatch(message);
89+
});
90+
});
91+
```

0 commit comments

Comments
 (0)