I am not able to run Jest tests on my components since it is not able to load html files. I get this error:
Error: Error: connect ECONNREFUSED 127.0.0.1:80
Followed by:
Unhandled Promise rejection: Failed to load landing.component.html
Running non-component tests is fine.
Here is my jest.config.js
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: "jest-preset-angular",
testEnvironment: "jsdom",
setupFilesAfterEnv: ["<rootDir>/setup-jest.ts"],
globals: {
"ts-jest": {
tsconfig: "<rootDir>/tsconfig.spec.json",
stringifyContentPathRegex: "\\.(html|svg)$",
},
},
snapshotSerializers: [
"jest-preset-angular/build/serializers/html-comment",
"jest-preset-angular/build/serializers/ng-snapshot",
"jest-preset-angular/build/serializers/no-ng-attributes",
],
moduleDirectories: ["node_modules", "."],
testMatch: ["**/+(*.)+(spec|test).+(ts|js)?(x)"],
transform: {
"^.+\\.(ts|js|html)$": "ts-jest",
},
resolver: "@nrwl/jest/plugins/resolver",
moduleFileExtensions: ["ts", "js", "html"],
coverageReporters: ["html"],
};
My setup-jest.ts
import 'jest-preset-angular/setup-jest';
And my tsconfig.spec.json
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/spec",
"module": "commonjs",
"types": ["jest", "node"],
"allowJs": true,
"esModuleInterop": true,
"emitDecoratorMetadata": true
},
"files": ["setup-jest.ts"],
"include": ["src/**/*.spec.ts", "src/**/*.d.ts"]
}
And the Jest portion from angular.json
"test": {
"builder": "@nrwl/jest:jest",
"options": {
"jestConfig": "jest.config.js",
"passWithNoTests": true
}
}
I am using Angular 12.2.7, Jest 27.2.4, jest-preset-angular 10.0.1 and ts-jest 27.0.5.