|
| 1 | +# jest-without-globals |
| 2 | + |
| 3 | +<!-- releases / versioning --> |
| 4 | +[](https://npmjs.org/package/jest-without-globals) |
| 5 | +[](https://github.com/agilgur5/jest-without-globals/releases) |
| 6 | +[](https://github.com/agilgur5/jest-without-globals/commits/master) |
| 7 | +<br><!-- downloads --> |
| 8 | +[](https://npmjs.org/package/jest-without-globals) |
| 9 | +[](https://npmjs.org/package/jest-without-globals) |
| 10 | +[](https://npmjs.org/package/jest-without-globals) |
| 11 | +[](https://npmjs.org/package/jest-without-globals) |
| 12 | +<br><!-- status / activity --> |
| 13 | +[](https://github.com/agilgur5/jest-without-globals/blob/master/src/index.ts) |
| 14 | +[](https://travis-ci.org/agilgur5/jest-without-globals) |
| 15 | +[](https://codecov.io/gh/agilgur5/jest-without-globals) |
| 16 | +<br> |
| 17 | +[](https://npmjs.org/package/jest-without-globals) |
| 18 | + |
| 19 | +Explicitly import [Jest](https://github.com/facebook/jest) globals. |
| 20 | + |
| 21 | +## Installation |
| 22 | + |
| 23 | +`npm i -D jest-without-globals` |
| 24 | + |
| 25 | +## Usage |
| 26 | + |
| 27 | +```typescript |
| 28 | +import { describe, it, expect } from 'jest-without-globals' |
| 29 | + |
| 30 | +describe('describe should create a section', () => { |
| 31 | + it('it should checkmark', () => { |
| 32 | + expect('').toBe('') |
| 33 | + }) |
| 34 | +}) |
| 35 | +``` |
| 36 | + |
| 37 | +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`. |
| 38 | + |
| 39 | +## Examples |
| 40 | + |
| 41 | +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. |
| 42 | + |
| 43 | +## How it works |
| 44 | + |
| 45 | +Basically just takes Jest's globals and exports them. |
| 46 | +The source code is currently shorter than this README, so [take a look under the hood](./src/)! :) |
| 47 | + |
| 48 | +## Credits |
| 49 | + |
| 50 | +Some inspiration for this came from [this workaround](https://github.com/facebook/jest/pull/7571#issuecomment-498634094) to avoid globals, which I had been using in projects previously. |
| 51 | +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. |
0 commit comments