eddyerburgh / eddyerburgh/vue-test-utils-karma-example

test usecase not working, need modification.

Open
#5 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
26
Forks
17
PR merge metrics
No merged PRs in 30d

Description

I clone the repo and run `npm i` then `npm run test`, however it's not display as expected:

```
07 12 2021 16:16:19.134:INFO [karma]: Karma v2.0.5 server started at http://0.0.0.0:9876/
07 12 2021 16:16:19.136:INFO [launcher]: Launching browser Chrome with unlimited concurrency
07 12 2021 16:16:19.154:INFO [launcher]: Starting browser Chrome
07 12 2021 16:16:19.996:INFO [Chrome 96.0.4664 (Windows 10 0.0.0)]: Connected on socket F4fijiOGcGpfsAE_AAAA with id 99121632

Counter.vue
× increments count when button is clicked
AssertionError: expected '0\n Increment' to include '1'
at Context.eval (webpack-internal:///32:15:86)

Chrome 96.0.4664 (Windows 10 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.022 secs / 0.012 secs)

=============================== Coverage summary ===============================
Statements : 100% ( 2/2 )
Branches : 100% ( 0/0 )
Functions : 100% ( 0/0 )
Lines : 100% ( 2/2 )
================================================================================
```

After some messing around, I found the original code is buggy.

The problematic source code is:

```js
describe("Counter.vue", () => {
it("increments count when button is clicked", () => {
const wrapper = shallowMount(Counter);
wrapper.find("button").trigger("click");
expect(wrapper.find("div").text()).contains("1");
});
});
```

I change it as follow, which works perfectly:

```js
describe("Counter.vue", () => {
it("increments count when button is clicked", () => {
const wrapper = shallowMount(Counter);
wrapper.find("button").trigger("click");
wrapper.vm.$nextTick().then(() => {
expect(wrapper.find("div").text()).contains("1");
});
});
});
```

Seems need writing `expect` in an async way instead.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.