-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Add ability to explicitly import global variables #4473
Comments
@aaronabramov is working on this, but it's not a high priority issue for now. |
Is now possible explicitly import only expect. For example, so: |
|
@SimenB But this is not for jest assertions? (In your require your not point to jest). What npm package do your mean? I need explicitly import jest assertions, like |
Jest assertions are in the |
how about the other variables? |
As of now that's not possible |
Exposing globals make it harder to type check as well: flow-typed/flow-typed#251 |
I understand that this is low priority, but could it be reopened until this feature has been implemented? |
We have also ditched jest, just because of absence of this. |
@NameFILIP I've always wondered about why testing frameworks use globals. Why is it a "good" idea? |
@lax4mike the quotes around "good" mean I'd prefer it to not be global |
I don't like globals either, so I'm wondering why they're so prevalent in this space. Any ideas? |
@lax4mike lock-in |
Jest Circus (#6295) will technically allow you to import all globals except for EDIT: you can import |
Lack of imagination and long series of copying what test frameworks have always done. For some bizarre reason, it's suddenly ok to use magic and globals in your JS as long as it's a test file. If anyone is interested in a powerful but minimalist alternative to Jest that doesn't use globals, take a look at substack/tape. Ideally, Jest would offer a similar interface to use explicit requires and plain functions. |
I have this problem when I enabled
in typescript, this is the workaround https://github.com/stherrienaspnet/nodejs-inversify-typescript-jest/blob/master/tsconfig.json
|
Duplicating my comment in a related PR as this issue seems to be more visible. import { describe, it, expect } from 'jest-without-globals'
describe('describe should create a section', () => {
it('it should checkmark', () => {
expect('').toBe('')
})
}) I'm currently using it in a few of my projects already and am planning on using it in all of my
Or AVA for something that's |
This will be available in the next version of Jest via #9801. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
While exposing global variables like
test
,expect
, etc. is a "good" idea, it would be nice to be able to avoid it and explicitly require/import it from a module. For example:The text was updated successfully, but these errors were encountered: