Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

511
Vistas
How to make ng test to fail on warnings

I've just finished fixing several warnings on my unit/component tests of my Angular app, that run using ng test (with Karma/Jasmine).

This process can be quite time-consuming as it is not always obvious to spot which test case(s) is actually causing the warning(s).

So now that I don't have any more warnings, I'm wondering if there is a way to make ng test to automatically fail whenever there are any warnings.

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Maybe something like this in test.ts or someplace where the tests get initialized.

console.warn = (message) => throw new Error(message);

I don't know if I would recommend this because warnings are just that warnings, but errors are errors and should be dealt with immediately. Where you would place this for just the tests can be tricky too.

over 4 years ago · Santiago Trujillo Denunciar

0

Define an extra file in your workspace root - called karma.globals.js for example which looks like:

// add globals for karma test runs
console.warn = (message) => { throw new Error(message); };

Now include it in your root karma.conf.js like:

const { join } = require('path');

module.exports = () => {
  return {
    
    // ...

    files: [
      join(__dirname, 'karma.globals.js')
    ]

    // ...
  };
};
over 4 years ago · Santiago Trujillo Denunciar

0

A simple and easy fix is a beforeAll block in your test.ts file. It replaces all console methods with an error function.

That way the tests will fail if you call console.log and you will know which ones.

If you still wanna use console.log within a unit being tested, then you could spy on it. But that's also bad due to shared global state.

Here's an example:

const errorFn = () => { throw new Error('No console logs!'); };
beforeAll(() => Object.keys(console).forEach((fn: string) => (console as any)[fn] = errorFn));

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda