Skip to content

Commit b29f039

Browse files
committed
doc(jest-angular): update README.md
1 parent 325928e commit b29f039

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

examples/apps/ng-app-cli/setup-jest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import 'jest-preset-angular/setup-jest.mjs';
12
import { env } from '@dotenv-run/core';
23
env({ root: '../../..', files: ['.env', '.env.app'] });
3-
import 'jest-preset-angular/setup-jest.mjs';
44

55
import '@angular/localize/init';
66
import { TextEncoder } from 'util';

packages/jest-angular/README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
## Install
22

3+
The package requires `jest-preset-angular@14` to be installed as a peer dependency.
4+
35
```sh
46
npm install --save-dev @dotenv-run/jest-angular
57
```
68

79
## Usage
810

9-
Add the following to your `jest.config.js`:
11+
Add the following to your `jest.config.js`, more information can be found in the [jest-preset-angular](https://thymikee.github.io/jest-preset-angular/docs/guides/esm-support/).
12+
13+
ESM support is required for Jest to understand `import.meta.env` notation.
1014

1115
```js
1216
const jestConfig = {
17+
// Required for ESM support
1318
preset: "jest-preset-angular/presets/defaults-esm",
1419
setupFilesAfterEnv: ["<rootDir>/setup-jest.ts"],
1520
testMatch: ["<rootDir>/src/app/**/*.(spec|jest).ts"],
16-
cache: false,
1721
moduleNameMapper: {
1822
"^rxjs(/operators$)?$":
1923
"<rootDir>/node_modules/rxjs/dist/bundles/rxjs.umd.js",
2024
tslib: "<rootDir>/node_modules/tslib/tslib.es6.mjs",
2125
},
26+
27+
// @dotenv-run/jest-angular transformer
2228
transform: {
2329
"^.+\\.(ts)$": [
2430
"@dotenv-run/jest-angular",
@@ -32,15 +38,18 @@ const jestConfig = {
3238
export default jestConfig;
3339
```
3440

35-
Create a `setup-jest.ts` file in your project root:
41+
Add the following to your `setup-jest.ts` file.
3642

3743
```ts
44+
// Required for ESM support
45+
import "jest-preset-angular/setup-jest.mjs";
46+
47+
// Load environment variables for Jest
3848
import { env } from "@dotenv-run/core";
3949
env({ root: "../../..", files: [".env", ".env.app"] });
40-
import "jest-preset-angular/setup-jest.mjs";
4150
```
4251

43-
Run your tests with `jest`.
52+
Run your tests with `jest`. More information can be found in the [Jest documentation](https://jestjs.io/docs/ecmascript-modules).
4453

4554
```sh
4655
NODE_OPTIONS=--experimental-vm-modules npx jest

0 commit comments

Comments
 (0)