-
Notifications
You must be signed in to change notification settings - Fork 19
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
How to use with jest? #49
Comments
Yes, the same question |
same issue, no idea how to setup jest tests with this great library |
I've just released a package that should help with the setup. Could you please give it a try? |
I have tried it but didn't make it work, I have different kinds of errors: This is my old jest.config where everything worked just fine:
Then I applied everything like the guide says:
Also created the jest-setup like so:
With this configuration, Jest is not able to parse the files in my project |
I'm facing the same issue, has anyone found some workaround? 🙂 |
Here's my working configuration (Angular 19) with the recommended syntax and using @dotenv-run/jest-angular: The jest.config.ts file : import presets from 'jest-preset-angular/presets';
const presetConfig = presets.createEsmPreset();
const jestConfig = {
...presetConfig,
setupFilesAfterEnv: ["<rootDir>/setup-jest.ts"],
testMatch: ["<rootDir>/src/app/**/*.(spec|jest).ts"],
moduleNameMapper: {
"^rxjs(/operators$)?$":
"<rootDir>/node_modules/rxjs/dist/bundles/rxjs.umd.js",
tslib: "<rootDir>/node_modules/tslib/tslib.es6.mjs",
"^.+\\.(css|scss)$": "identity-obj-proxy",
},
transform: {
"^.+\\.(ts|mjs|js|html)$": [
"@dotenv-run/jest-angular",
{
useESM: true,
stringifyContentPathRegex: "\\.(html|svg)$",
tsconfig: "<rootDir>/tsconfig.spec.json",
},
],
},
transformIgnorePatterns: [
"node_modules/(?!.*\\.mjs$)"
],
collectCoverage: true,
coverageReporters: ["html", "text-summary"],
};
export default jestConfig; And the setup-jest.ts (you can modify it to use zone.js, juste remove "less"): import { setupZonelessTestEnv } from 'jest-preset-angular/setup-env/zoneless/index.mjs';
setupZonelessTestEnv();
import { env } from "@dotenv-run/core";
env({ root: "../../..", files: [".env", ".env.app"] }); My tesconfig.spec.ts: {
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/spec",
"types": [
"jest"
]
},
"include": [
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
} |
TypeError: Cannot read properties of undefined (reading 'NG_APP_GRAPHQL_ENDPOINT')
Looks like @ngx-env/builder is not loaded, how I can setup env from code. I would probably put it in setupJest.ts file, where it will be loaded on jest startup.
The text was updated successfully, but these errors were encountered: