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

[WIP] test: let's use vite-jest for testing #82

Closed
wants to merge 2 commits into from

Conversation

haoqunjiang
Copy link

@haoqunjiang haoqunjiang commented Dec 7, 2021

First, thanks for the great example app!

I was developing vite-jest and used this repository as a real-world test case.
Now after v0.1.3 all the current tests are passing. So I'm opening this PR in case you are interested in joining the experiment of this new vite-jest integration.

Main changes in this PR:

  • removed babel-jest, ts-jest in favor of vite-jest
  • a few refactors as all test specs are native ES modules now:
    • jest object is imported from @jest/globals
    • use jest.unstable_mockModule instead of jest.mock
  • added 3 @ts-expect-error comments to pass the git pre-commit hook. These type checkings seem to have been failing before my refactor.

The coverage report is not working at the moment, though.

@vercel
Copy link

vercel bot commented Dec 7, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/mutoe/vue3-realworld-example-app/EGDdwLaVHXYH6AfyWMzzPFEe9z4W
✅ Preview: https://vue3-realworld-example-app-git-fork-sodatea-vite-jest-mutoe.vercel.app

@mutoe
Copy link
Owner

mutoe commented Dec 10, 2021

@sodatea Sounds great, bro. I don't know if you represent the official Vite, but before it is officially released (at least the beta), I think this can only be pending, or merged into a separate branch for tracking :)

jest.mock('src/services/comment/getComments')
jest.mock('src/services/comment/postComment')
jest.unstable_mockModule('src/services/comment/getComments', () => ({
getCommentsByArticle: jest.fn(),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether I still need to declare the mocked function here? Is it necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is necessary. The jest mock API for ES modules only accepts a factory function for now, so the exports must be mocked and returned from that factory function.

@haoqunjiang
Copy link
Author

but before it is officially released (at least the beta), I think this can only be pending, or merged into a separate branch for tracking :)

Yeah, it makes sense. I'll ping you again when the package reaches beta.

# Conflicts:
#	src/components/ArticleDetail.spec.ts
#	src/components/ArticleDetailComments.spec.ts
#	src/components/ArticlesList.spec.ts
#	src/components/ArticlesList.vue
@mutoe mutoe changed the title test: let's use vite-jest for testing [WIP] test: let's use vite-jest for testing Dec 20, 2021
@mutoe
Copy link
Owner

mutoe commented Dec 11, 2023

Hi @sodatea , after the release of Vitest version 1.0, this project has been migrated to Vitest. Also this PR has been too long, close it for now. Welcome to open it again if necessary :D

@mutoe mutoe closed this Dec 11, 2023
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

Successfully merging this pull request may close these issues.

2 participants