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

Introduction to React Testing: Import Vitest functions #28253

Closed
2 of 5 tasks
MaoShizhong opened this issue Jun 21, 2024 · 2 comments · Fixed by #28254
Closed
2 of 5 tasks

Introduction to React Testing: Import Vitest functions #28253

MaoShizhong opened this issue Jun 21, 2024 · 2 comments · Fixed by #28254
Assignees

Comments

@MaoShizhong
Copy link
Contributor

MaoShizhong commented Jun 21, 2024

Checks

Describe your suggestion

Description

A previous open PR for this fell through, so re-opening an issue for someone to be assigned.

In the Introduction to React Testing lesson, our code examples of tests use Vitest's globals, due to the setup guide including globals: true in vite.config.js.

While this allows the tests to work without errors when running Vitest, ESLint (which comes by default) will still complain about undefined variables. The fix for this is iffy, as ESLint doesn't have Vitest globals built in as an environment, meaning you'd have to enable the Jest environment then manually add individual Vitest-specific globals. This is a lot of faff learners face, just to use Vitest globals. A better resolution would be to just import the Vitest functions needed. No ESLint shenanigans, you don't have to mess with globals and you get better intellisense for those functions anyway, as they won't be typed as any.

Please comment below if you'd like to be assigned to work on this issue. Please do not start any work until you have been formally assigned by a maintainer.

Acceptance criteria

  • In the Introduction to React Testing lesson, any code blocks including Vitest functions like describe, expect or it will need to have them imported in the code block.
  • Add the following note box (provided wording is just a suggestion) immediately after the first test code example (which is the 2nd code block):
    <div class="lesson-note" markdown="1">
    
    #### Vitest globals and ESLint
    
    Even if you set `globals: true` in `vite.config.js` like in the setup tutorial, ESLint will still yell at you, as it will not recognize these globals without some extra stuff in your ESLint configuration file. The most straightforward resolution would be to explicitly import the globals you'd need. You can omit `globals: true` from `vite.config.js` in this case.
    
    </div>

Path

Ruby / Rails, Node / JS

Lesson Url

https://www.theodinproject.com/lessons/node-path-react-new-introduction-to-react-testing#our-first-query

(Optional) Discord Name

No response

(Optional) Additional Comments

No response

@MaoShizhong MaoShizhong added the Status: Help Wanted This issue can be assigned to other contributors label Jun 21, 2024
@mathdebate09
Copy link
Contributor

Coincidentally, this was the exact lesson I was going through today :D
I'd love to work this issue up

@MaoShizhong MaoShizhong removed the Status: Help Wanted This issue can be assigned to other contributors label Jun 21, 2024
@MaoShizhong
Copy link
Contributor Author

Go for it - assigned

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