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

test usecase not working, need modification. #5

Open
Nick-Hopps opened this issue Dec 7, 2021 · 0 comments
Open

test usecase not working, need modification. #5

Nick-Hopps opened this issue Dec 7, 2021 · 0 comments

Comments

@Nick-Hopps
Copy link

Nick-Hopps commented Dec 7, 2021

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:

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:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant