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

[useAxios] Test case missing url doesn't pass. #2478

Closed
7 tasks done
yysuen opened this issue Nov 26, 2022 · 0 comments · Fixed by #2484
Closed
7 tasks done

[useAxios] Test case missing url doesn't pass. #2478

yysuen opened this issue Nov 26, 2022 · 0 comments · Fixed by #2484

Comments

@yysuen
Copy link
Contributor

yysuen commented Nov 26, 2022

Describe the bug

In a word

Here's the original output of Vitest.
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  packages/integrations/useAxios/index.test.ts > useAxios > missing url
AssertionError: expected undefined not to be undefined
 ❯ packages/integrations/useAxios/index.test.ts:281:25
    279|     const { execute } = useAxios(und…
    280|     const { error } = await execute()
    281|     expect(error.value).toBeDefined()
       |                         ^
    282|   })
    283| })

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯

 Test Files  1 failed | 125 passed (126)
      Tests  1 failed | 813 passed (814)
   Start at  19:11:09
   Duration  99.82s


 FAIL  Tests failed. Watching for file changes...

About the reason

After logging, I found that error.value here is undefined.

The reason is that in execute function, _url is assigned a default '' (empty string) when it's undefined. Therefore, axios doesn't walk into the catch branch.

My solution

I'll open a PR later and mention it below.

Reproduction

Clone https://github.com/syy11cn/vueuse and run pnpm run test.

System Info

System:
    OS: macOS 13.0.1
    CPU: (8) arm64 Apple M2
    Memory: 59.03 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.17.0 - ~/.nvm/versions/node/v16.17.0/bin/node
    npm: 8.15.0 - ~/.nvm/versions/node/v16.17.0/bin/npm
  Browsers:
    Chrome: 107.0.5304.110
    Safari: 16.1

Used Package Manager

pnpm

Validations

wheatjs added a commit that referenced this issue Jan 9, 2023
…lose #2478) (#2484)

* fix(useAxios): assign AxiosError to error.value when no url provided

* fix(useAxios): remove default empty string for request url

Co-authored-by: wheat <jacobrclevenger@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant