https://github.com/agilgur5/jest-without-globals
Explicitly import Jest globals
https://github.com/agilgur5/jest-without-globals
explicit export globals import jest module test
Last synced: 6 months ago
JSON representation
Explicitly import Jest globals
- Host: GitHub
- URL: https://github.com/agilgur5/jest-without-globals
- Owner: agilgur5
- License: other
- Created: 2019-12-08T01:03:21.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-04-13T19:24:53.000Z (over 5 years ago)
- Last Synced: 2025-01-14T00:23:19.257Z (6 months ago)
- Topics: explicit, export, globals, import, jest, module, test
- Language: TypeScript
- Size: 371 KB
- Stars: 9
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# jest-without-globals
[](https://npmjs.org/package/jest-without-globals)
[](https://github.com/agilgur5/jest-without-globals/releases)
[](https://github.com/agilgur5/jest-without-globals/commits/master)
[](https://npmjs.org/package/jest-without-globals)
[](https://npmjs.org/package/jest-without-globals)
[](https://npmjs.org/package/jest-without-globals)
[](https://npmjs.org/package/jest-without-globals)
[](https://github.com/agilgur5/jest-without-globals/blob/master/src/index.ts)
[](https://travis-ci.org/agilgur5/jest-without-globals)
[](https://codecov.io/gh/agilgur5/jest-without-globals)
[](https://npmjs.org/package/jest-without-globals)Explicitly import [Jest](https://github.com/facebook/jest) globals.
## Installation
`npm i -D jest-without-globals`
_(note that `jest` is a peer dependency)_
## Usage
```typescript
import { describe, it, expect } from 'jest-without-globals'describe('describe should create a section', () => {
it('it should checkmark', () => {
expect('').toBe('')
})
})
```All of the functions available in [Jest's API](https://jestjs.io/docs/en/api), as well as `jest` and `expect`, can be imported from `jest-without-globals`.
## Examples
Can take a look at the [tests](./test/) for usage of more of the globals, but basically you can now just `import` any Jest global.
## How it works
Basically just takes Jest's globals and exports them.
The source code is currently shorter than this README, so [take a look under the hood](./src/)! :)## Credits
Some inspiration came from [this workaround](https://github.com/facebook/jest/pull/7571#issuecomment-498634094) to avoid globals, which I had been using in projects previously.
I wanted a package I could re-use in all my projects' tests instead of constantly having to create a helper file and map its name, and so `jest-without-globals` was born!Can also see [my PR](https://github.com/facebook/jest/pull/9306) for implementing this directly in Jest. It also adds a `noJestGlobals` configuration option that would prevent these globals from being inserted into your environment as well (which is something that isn't possible with a simple user-land library like this).