Search code examples
javascriptangulartypescriptunit-testingkarma-jasmine

How to log value in karma


Hi I'm trying to console log / console error from karma tests - but there is no any logs in terminal!

 it('should not delete card on deleteCard method if user cancels', async(() => {
    const eventMock = jasmine.createSpyObj('event', ['preventDefault', 'stopPropagation']);
    const testCard = testCards[1];
    cardsServiceSpy.deleteCard.calls.reset();
    actionSheetDismissService.canDismiss.and.returnValue(Promise.resolve(false));
    console.log(testCard);
    component.deleteCard(eventMock, testCard).then((dataOnDelete) => {
      console.log(dataOnDelete);
      expect(dataOnDelete).toBe(testCard.id);
      expect(cardsServiceSpy.deleteCard).not.toHaveBeenCalled();
      expect(component.cards.length).toBe(3);
    });
  }));

What I'm missing???


Solution

  • module.exports = function (config) {
     config.set({
     basePath: '',
     frameworks: ['jasmine', '@angular-devkit/build-angular'],
     plugins: [
       require('karma-jasmine'),
       require('karma-chrome-launcher'),
       require('karma-jasmine-html-reporter'),
       require('karma-coverage'),
       require('@angular-devkit/build-angular/plugins/karma')
     ],
     client: {
       jasmine: {
        // you can add configuration options for Jasmine here
        // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
        // for example, you can disable the random execution with `random: false`
        // or set a specific seed with `seed: 4321`
       },
       clearContext: false, // leave Jasmine Spec Runner output visible in browser
       captureConsole: true,    
     },
      // ...........
      // ...........
    });
    };
    

    Set captureConsole flag to true, in karma.conf.js file.