Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

787
Views
No se pueden ejecutar pruebas Jest para componentes (Error al cargar archivos html)

No puedo ejecutar pruebas Jest en mis componentes ya que no puede cargar archivos html. me sale este error:

 Error: Error: connect ECONNREFUSED 127.0.0.1:80

Seguido por:

 Unhandled Promise rejection: Failed to load landing.component.html

Ejecutar pruebas sin componentes está bien.

Aquí está mi 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"], };

Mi setup-jest.ts

 import 'jest-preset-angular/setup-jest';

Y mi 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"] }

Y la parte de Jest de angular.json

 "test": { "builder": "@nrwl/jest:jest", "options": { "jestConfig": "jest.config.js", "passWithNoTests": true } }

Estoy usando Angular 12.2.7, Jest 27.2.4, jest-preset-angular 10.0.1 y ts-jest 27.0.5.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Esta respuesta me ayudó a resolver este problema. Como se desaconsejan las respuestas de solo enlace, a continuación he incluido la respuesta original de bnjmnhnndrsn .

Encontré este problema específico recientemente y la creación de su propio preprocesador de transformación lo resolverá. Esta fue mi configuración:

paquete.json

 "jest": { "moduleFileExtensions": [ "js", "html" ], "transform": { "^.+\\.js$": "babel-jest", "^.+\\.html$": "<rootDir>/test/utils/htmlLoader.js" } }

NOTA: babel-jest normalmente se incluye de forma predeterminada, pero si especifica un preprocesador de transformación personalizado, parece que tiene que incluirlo manualmente.

prueba/utils/htmlLoader.js:

 const htmlLoader = require('html-loader'); module.exports = { process(src, filename, config, options) { return htmlLoader(src); } }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!